[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: converting modules in written in C for Lua 5.1 to Lua 5.2
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Sat, 29 Sep 2012 08:09:44 -0300
> Is there are a guide somewhere on converting modules written in C for
> Lua 5.1 to Lua 5.2?
There is no guide AFAIK, but I've been converting my modules at
http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/ and it's been quite easy.
The changes are almost always these:
-- luaL_setmetatable is new in 5.2:
< luaL_getmetatable(L,MYTYPE);
< lua_setmetatable(L,-2);
---
> luaL_setmetatable(L,MYTYPE);
-- C modules don't set globals
< lua_setglobal(L,MYNAME);
< luaL_register(L,MYNAME,R);
---
> luaL_setfuncs(L,R,0);
-- use either luaL_setfuncs or luaL_newlib depending on whether your module
-- table is the metatable for its objects (that's the lazy way I do it)
< luaL_register(L,MYNAME,R);
---
> luaL_newlib(L,R);