below is the lua table I have to read from C:
listen = { { port = 1234, address = "192.168.1.1", userdata = "liunx" }, { port = 1235, address = "192.168.1.2", userdata = "liunx1" }, { port = 1236, address = "192.168.1.3", userdata = "liunx2" } }
below is the c code:
#include <lua.h> /* Always include this when calling Lua */ #include <lauxlib.h> /* Always include this when calling Lua */ #include <lualib.h> /* Prototype for luaL_openlibs(), */ /* always include this when calling Lua */ #include <stdlib.h> /* For function exit() */ #include <stdio.h> /* For input/output */ void bail(lua_State *L, char *msg){ fprintf(stderr, "\nFATAL ERROR:\n %s: %s\n\n", msg, lua_tostring(L, -1)); exit(1); } int main(void) { lua_State *L; L = luaL_newstate(); /* Create Lua state variable */ luaL_openlibs(L); /* Load Lua libraries */ if (luaL_loadfile(L, "cfg.lua")) bail(L, "luaL_loadfile() failed"); if (lua_pcall(L, 0, 0, 0)) bail(L, "lua_pcall() failed"); // how to read??? lua_getglobal(L, "listen"); lua_close(L); return 0; }
I want to move this table, which may contain some data during the loop, but I really don't know how to do this, so any advice?
Thanks for the tips! Below is the code:
#include <lua.h> /* Always include this when calling Lua */
liunx source share