[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to load lua extensions using C API?
- From: Sean Conner <sean@...>
- Date: Thu, 8 Aug 2013 14:13:59 -0400
It was thus said that the Great Luiz Henrique de Figueiredo once stated:
> > If you want to use require, you could always do (after calling
> > luaL_openlibs()):
> >
> > lua_getglobal(L,"package");
> > lua_getfield(L,-1,"preload");
> > lua_pushcfunction(L,luaopen_nameofyourmodule);
> > lua_setfield(L,-2,"nameofyourmodule");
>
> It's simpler to use luaL_requiref:
> luaL_requiref(L,"nameofyourmodule",luaopen_nameofyourmodule)
>
> See http://www.lua.org/manual/5.2/manual.html#luaL_requiref
Ah. I'm still using 5.1 [1] so I didn't realize that function existed.
Thanks.
-spc
[1] I'm a bit hesitant to upgrade. I'm using 5.1 at work, and I'd hate
to lose the option of using LuaJIT (not that I'm really using it
now, but it's still an option for some of our platforms).