lua-users home
lua-l archive

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

steve donovan wrote
> On Wed, May 8, 2013 at 11:55 AM, Are Leistad 
> <
> >
>  wrote:
>> I shall go with the flow for new projects. Oh, and sorry for the typos, I
>> was knackered, after many hours of Lua'ing. It was too much fun to
>> sleep...
> Oh we all know that!  I wouldn't worry that much about module(), it isn't
> intrinsically evil (but using package.seeall will not gain you friends
> among those who want to use your code in a sandbox!)
> Most of the differences between 5.1 and 5.2 are made easier by the fact
> that 5.2 is usually compiled with LUA_COMPAT_ALL.  So these things are
> already defined:
> #define lua_strlen(L,i)        lua_rawlen(L, (i))
> #define lua_objlen(L,i)        lua_rawlen(L, (i))
> #define lua_equal(L,idx1,idx2)       
> lua_compare(L,(idx1),(idx2),LUA_OPEQ)
> #define lua_lessthan(L,idx1,idx2)    lua_compare(L,(idx1),(idx2),LUA_OPLT)
> So (unless you make use of function environments) mostly it boils down to
> the module entry point, and the difference can be easily #ifdefed:
> EXPORT int luaopen_mylib (lua_State *L) {
> #if LUA_VERSION_NUM > 501
>     lua_newtable(L);
>     luaL_setfuncs (L,mylib_funs,0);
>     lua_pushvalue(L,-1);        // pluck these lines out if they offend
> you
>     lua_setglobal(L,"mylib"); // for they clobber the Holy _G
> #else
>     luaL_register(L,"mylib",mylib_funs);
> #endif
>     return 1;
> }
> Another issue that a porter will find with historical code is that it may
> contain Lua 5.0-isms that have finally been end-of-lifed.
> For instance, luaL_reg is now spelt luaL_Reg, for both 5.1/5.2.  Some of
> the buffer macros likewise.
> steve d.

Thank you , Steve!

I'm beginning to get acclimatized to "the new ways" now that I've gotten a
few tastes of it. I can certainly see the point in leaving _G alone.

> Which means (to anticipate the obvious) that you have to define
> LUA_COMPAT_ALL in your code or build.
> Authoritative list of differences is here:
> Note that lua_cpcall is also defined as a macro with LUA_COMPAT_ALL. The
> absence of luaL_typerror can be a bitch, however, and watch out for
> lua_load and lua_resume's extra parameter...

Luckily, LUA_COMPAT_ALL saved me in this instance. I see that luaL_openlib
isn't mentioned in the 5.2 changes, so it's clear I've been away for too
long :-)


View this message in context:
Sent from the Lua-l mailing list archive at