There's an excellent example of Lua-C integration here and here.
If you just need to export a function into the global namespace, then:
Declare the function (let's call it f) with signature lua_CFunction.
Call lua_register(L, "myfunc", f), with L being the Lua state, and function = f.
Run the lua code. Then f will be available in the global namespace as myfunc.
If you're going to use the stock interpreter then you might want to make a library. This guy wrote an article for Lua Programming Gems that explains how to do it. The sources are available online.
发布评论
评论(2)
这里和此处。
如果您只需要将函数导出到全局命名空间,那么:
lua_CFunction
声明该函数(我们称之为f
)。f
。f
将在全局命名空间中作为myfunc
使用。如果您要使用库存解释器,那么您可能需要创建一个库。 这个人为Lua 编程宝石 解释了如何做到这一点。来源可在线获取。
There's an excellent example of Lua-C integration here and here.
If you just need to export a function into the global namespace, then:
f
) with signaturelua_CFunction
.lua_register(L, "myfunc", f)
, with L being the Lua state, and function =f
.f
will be available in the global namespace asmyfunc
.If you're going to use the stock interpreter then you might want to make a library. This guy wrote an article for Lua Programming Gems that explains how to do it. The sources are available online.
您可以使用 luaL_register 注册函数。
请参阅PiL
You can register functions using luaL_register
Look at some examples and explanation in PiL