首页 > 解决方案 > 使用 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;

标签: exportadaconventions

解决方案


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.


推荐阅读