[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to load lua extensions using C API?
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Thu, 8 Aug 2013 14:41:23 -0300
> 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