lua-users home
lua-l archive

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

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},

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

** 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!