export - 使用 pragma 约定而不导出
问题描述
我需要使用 Lua 的 Ada 库。我想使用一个通用包,它与其他数据一起包含一个函数,该函数将根据数据在 Lua 中注册不同的名称。据我了解,我应该将此函数声明为“with Export, Convention => C”,但是当实例化此类包的多个实例时,该库将包含多个具有相同名称的函数,并且无法编译。在这种情况下是否可以不使用“Export”,而只使用“Convention => C”,因为在 Lua 中仅使用函数引用进行注册?
with System; use System;
with Interfaces.C; use Interfaces.C;
generic
type Data is private;
Name : String;
package P is
function Call (Lua : Address) return int
with Export, Convention => C;
function Get_Name return String is (Name);
end P;
解决方案
You only need Export
if the function needs to be visible to a linker (for example, when you have C code explicitly calling this function). If you only need to pass the function via pointer into the Lua runtime, Convention => C
on the function suffices, though you also need another Convention => C
on the function pointer type.
推荐阅读
- javascript - 语音合成在页面加载时不断说话
- javascript - 在 gtm 加载之前未触发 Google 跟踪代码管理器 JavaScript 错误触发器
- sql - 找出哪个员工接受了更多培训
- python - 通过弹出删除最后一个列表元素
- spring-boot - 如何使用 CriteriaBuilder 的多个 JOIN 来构建 Predicate?
- vba - 如何在不同的工作表上创建 tabledestination
- c++ - 我尝试从其他类调用函数并且输出是乱码
- java - 如何在一个范围内获得给定数字的随机倍数
- python - 我的 Pygame 角色没有连续移动
- python - 如何在 VScode 中显示 pylint 消息代码?