lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



Am 08.12.2012 um 14:25 schrieb liam mail:

On 8 December 2012 12:28, Philipp Kraus <philipp.kraus@flashpixx.de> wrote:

Am 08.12.2012 um 11:40 schrieb Luiz Henrique de Figueiredo:

luaL_register(L,"org.conman.math",reg_math);
Never had a problem.

This no longer works is 5.2 because in 5.1 luaL_register called
(the undocumented and badly named) luaL_findtable which did that magic,
but 5.2 lacks luaL_findtable.

If you want to keep this way of registering your libraries is 5.2,
but don't want to use or require LUA_COMPAT_MODULE when build Lua,
you can copy luaL_findtable from the 5.2 source and use this version
of luaL_register:

void luaL_register(lua_State *L, const char *libname, const luaL_Reg *l) {
lua_pushglobaltable(L);
luaL_findtable(L,-1,libname,0);
luaL_setfuncs(L,l,0);
}


The findtable call does not exists. I have include the files
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>

Do I have forgot an include? I'm using Lua 5.2.1

Thanks

Phil


If you want to keep this way of registering your libraries is 5.2,
but don't want to use or require LUA_COMPAT_MODULE when build Lua,
you can copy luaL_findtable from the 5.2 source and use this version
of luaL_register:

You will find it in lauxlib.c line 764 guarded by a LUA_COMPAT_MODULE macro.

Which version is the newer calls for 5.2 without the macro?
At the moment I use

lua_pushglobaltable( m_lua );
//luaL_findtable( m_lua, -1, p_libname.c_str(), 0 );
luaL_setfuncs( m_lua, &l_functions[0], 0);

l_functions is a vector of luaL_Reg elements and the terminator item. I need to set up
a "name" for my global table

Thanks

Phil