lua 5.1 doubts

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

lua 5.1 doubts

Walter Cruz
Hi all. I've compiled lua 5.1 but I have some doubts:

1) Why the LUA_COMPAT_LOADLIB is not defined by default in luaconf.h?
2) Do I need still use the compat.lua?

[]'s
- Walter
Reply | Threaded
Open this post in threaded view
|

Re: lua 5.1 doubts

Craig Mason-Jones
Hi Walter,

As I understand it, compat-5.1 is to make lua 5.0 module / package
compatible with 5.1, so that 'require', etc all work as expected in 5.1.
So, if you're using 5.1, you don't need the COMPAT_LOADLIB, etc, nor
compat-5.1.lua

All the best,
Craig

Walter Cruz wrote:

> Hi all. I've compiled lua 5.1 but I have some doubts:
>
> 1) Why the LUA_COMPAT_LOADLIB is not defined by default in luaconf.h?
> 2) Do I need still use the compat.lua?
>
> []'s
> - Walter


Reply | Threaded
Open this post in threaded view
|

Re: lua 5.1 doubts

Walter Cruz
Hi Craig.

If I don't define the LUA_COMPAT_LOADLIB I can't use loadlib on lua 5.1.

There's some documentation about lua 5.1?

[]'s
- Walter

Reply | Threaded
Open this post in threaded view
|

Re: lua 5.1 doubts

Craig Mason-Jones
Ah, so I see... after some fiddling I found:

1. (I'm working in Lua 5.1 under Windows with Microsoft Visual C++
compiler, so please excuse)

2. I had to recompile my module to work under Lua 5.1, and added a
function called
  int luaopen_wstring(lua_State* s)
  which called luaL_openlib(..)
  to register my library with Lua.

3. Then in Lua 5.1, I had only to go : x = require('wstring')

If you like, I can send you my source code for my wstring library - it's
just a demo library for something I was trying out. As I said, it's in
VC++, but I'm sure the concept is good. I don't know where this is
documented, I hacked the source from LuaExpat 1.0.1's code, right at the
bottom of lxplib.c:


static const struct luaL_reg lxp_meths[] = {
  {"parse", lxp_parse},
    ....
  {NULL, NULL}
};

static const struct luaL_reg lxp_funcs[] = {
  {"new", lxp_make_parser},
  {NULL, NULL}
};


/*
** Assumes the table is on top of the stack.
*/
static void set_info (lua_State *L) {
    lua_pushliteral (L, "_COPYRIGHT");
    lua_pushliteral (L, "Copyright (C) 2003-2005 Kepler Project");
    lua_settable (L, -3);
    lua_pushliteral (L, "_DESCRIPTION");
    lua_pushliteral (L, "LuaExpat is a SAX XML parser based on the Expat
library");
    lua_settable (L, -3);
    lua_pushliteral (L, "_NAME");
    lua_pushliteral (L, "LuaExpat");
    lua_settable (L, -3);
    lua_pushliteral (L, "_VERSION");
    lua_pushliteral (L, "1.0.1");
    lua_settable (L, -3);
}


int luaopen_lxp (lua_State *L) {
  luaL_newmetatable(L, ParserType);
  lua_pushliteral(L, "__index");
  lua_pushvalue(L, -2);
  lua_rawset(L, -3);
  luaL_openlib (L, NULL, lxp_meths, 0);
  luaL_openlib (L, "lxp", lxp_funcs, 0);
  set_info (L);

  return 1;
}

I skip all but the luaL_openlib(L, "wstring", wstring_funcs,0) , which
seems to work well.

Good luck!
Craig

Reply | Threaded
Open this post in threaded view
|

Re: lua 5.1 doubts

Walter Cruz
:)

Hey Craig, cand you send me your wstring code?

[]'s
- Walter