converting modules in written in C for Lua 5.1 to Lua 5.2

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

converting modules in written in C for Lua 5.1 to Lua 5.2

Marc Balmer
Hi

Is there are a guide somewhere on converting modules written in C for
Lua 5.1 to Lua 5.2?  I did not even find a document listing the changes
in 5.2 vs. 5.1, but maybe my search was "flaky" ;)

Thanks,
Marc

Reply | Threaded
Open this post in threaded view
|

Re: converting modules in written in C for Lua 5.1 to Lua 5.2

Rob Hoelz-2
On Sat, 29 Sep 2012 10:07:24 +0200
Marc Balmer <[hidden email]> wrote:

> Hi
>
> Is there are a guide somewhere on converting modules written in C for
> Lua 5.1 to Lua 5.2?  I did not even find a document listing the
> changes in 5.2 vs. 5.1, but maybe my search was "flaky" ;)
>
> Thanks,
> Marc
>

Hi Marc!

You might find this section of the manual useful:

http://www.lua.org/manual/5.2/manual.html#8

I confess I haven't looked at 5.2 much, though!

-Rob

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: converting modules in written in C for Lua 5.1 to Lua 5.2

Luiz Henrique de Figueiredo
In reply to this post by Marc Balmer
> 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);


Reply | Threaded
Open this post in threaded view
|

Re: converting modules in written in C for Lua 5.1 to Lua 5.2

liam mail
On 29 September 2012 12:09, Luiz Henrique de Figueiredo
<[hidden email]> wrote:

> -- luaL_setmetatable is new in 5.2:
>
> <  luaL_getmetatable(L,MYTYPE);
> <  lua_setmetatable(L,-2);
> ---
>>  luaL_setmetatable(L,MYTYPE);
>

Out of interest is there a reason for making such uses of code only
compatible with 5.2 rather than get and set which is valid for both
5.1 and 5.2?

Liam

Reply | Threaded
Open this post in threaded view
|

Re: converting modules in written in C for Lua 5.1 to Lua 5.2

Luiz Henrique de Figueiredo
> Out of interest is there a reason for making such uses of code only
> compatible with 5.2 rather than get and set which is valid for both
> 5.1 and 5.2?

You have a point, portability and minor impact when upgrading is important,
but I try to make my libraries use the best API in each version, since
they're probably taken as a showcase for the Lua API (for better or worse).
I do maintain separate versions of my libraries.

Reply | Threaded
Open this post in threaded view
|

Re: converting modules in written in C for Lua 5.1 to Lua 5.2

Tomás Guisasola-2
In reply to this post by Marc Balmer
  Hi Marc

> Is there are a guide somewhere on converting modules written in C for
> Lua 5.1 to Lua 5.2?  I did not even find a document listing the changes
> in 5.2 vs. 5.1, but maybe my search was "flaky" ;)
  I wrote down some hints on making code compatible to all 5.X
versions:

http://lua-users.org/wiki/CompatibilityWithLuaFive

  The difficulty depends on the code, of course :-) Take a look
at the page and tell if you find it useful.  And feel free to improve
the page.

  Regards,
  Tomás