[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: I Can't Get Lua 5.1 and IUP 3.30 to Work With VSCode and GCC on Windows 10 x64
- From: Sean Conner <sean@...>
- Date: Mon, 25 Oct 2021 03:28:30 -0400
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