I'm looking for a way to be able to read lua's main function in my c code.
I'm also looking for a way to pass a C function to lua
In my sample code LoadTBL
would be the function that comes from the C code
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 code:
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");
}
The idea is to create luas scripts that can interact with C codes