我正在寻找一种方法,能够在我的c代码中读取Lua的main函数.
我还在寻找一种将C函数传递给Lua的方法
在我的样例代码中,LoadTBL
是来自C代码的函数
TBL =
{
{ Init, 0, 15, 00 },
{ End, 1, 16, 00 }
}
function main()
for key, value in pairs(TBL) do
result, msg = LoadTBL(value[1], value[2], value[3]);
if( not result ) then return false, msg;
end
end
return true, "success";
end
C代码:
int LoadTBL (int val1, int val2, int val3) {
....
return 0;
}
void read_test(void) {
lua_State *L;
L = luaL_newstate();
luaL_openlibs(L);
if (luaL_loadfile(L, "test.lua") || lua_pcall(L, 0, 0, 0))
{
printf("Error 'test.lua'\n");
return;
}
lua_close(L);
printf("Read complete.\n");
}
我们的 idea 是创建可以与C代码交互的Luas脚本