|
I tried the suggested changes, but the original test script worked fine while this gave me the following error: C:\Users\name\AppData\Local\Temp\ccGhaL5y.o: In function `main': C:/Users/name/Desktop/Apps/test/embed.c:62:warning: implicit declaration of function 'luaL_setfuncs'; did you mean 'lua_setfenv'? [-Wimplicit-function-declaration] luaL_setfuncs(L,preloaders,0); ^~~~~~~~~~~~~ lua_setfenv C:\Users\name\AppData\Local\Temp\ccGhaL5y.o: In function `main': C:/Users/name /Desktop/Apps/test/embed.c:62: undefined reference to `luaL_setfuncs ' collect2.exe: error: ld returned 1 exit status From: Sean Conner It was thus said that the Great nerditation once stated: > On 2021/10/24 5:18, Kaz wrote: > > > > What should I put into the files to test? > > try this piece of code which demonstrates the usage of Lua and iuplua from > C. this should be copy-paste ready. > > ```C > #include <stdio.h> > > #include <lua.h> > #include <lualib.h> > #include <lauxlib.h> > > #include <iup.h> > #include <iuplua.h> > Starting from here: > typedef struct { > char const *name; > lua_CFunction loaderfn; > } Preloader; > > /* list the Lua modules you want to preload here */ > static const Preloader preloaders[] = { > { "iuplua", &iuplua_open }, > { NULL, NULL }, > }; to here, can be replaced with: static luaL_Reg const preloaders[] = { { "iuplua" , &iuplua_open }, { NULL , NULL } }; > int main(int argc, char const *argv[]) > { > /* do something in C */ > printf("hello C!\n"); > > /* init Lua runtime */ > lua_State *L = luaL_newstate(); > luaL_openlibs(L); > > /* try run some Lua code */ > luaL_dostring(L, "print 'hello Lua!'"); > > /* install preloaders into package.preload */ > lua_getglobal(L, "package"); > lua_getfield(L, -1, "preload"); And from here: > Preloader const *mod = &preloaders[0]; > while (mod->name != NULL) { > lua_pushcfunction(L, mod->loaderfn); > lua_setfield(L, -2, mod->name); > ++mod; > } to here, replace with: luaL_setfuncs(L,preloaders,0); > lua_pop(L,2); > /* try run some more Lua code with iup */ > luaL_dostring(L, "local iup = require 'iuplua'; iup.Message('hello', 'hello iuplua!');"); > > lua_close(L); > return 0; > } > ``` Just FYI. -spc |