lua-users home
lua-l archive

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

I don't know about the AV, but this code only runs with Lua 5.0.2. Lua 5.1 changed the way loaders are called. See [1] for more info.


I haven't worked with Lua 5.1 yet, but from it's sources I think you should do something like this:

  L:= lua_open(); // or luaL_newstate();

  lua_pushcfunction(L, luaopen_base);
  lua_pushstring(L, '');
  lua_call(L, 1, 0);

  lua_pushcfunction(L, luaopen_string);
  lua_pushstring(L, 'string');
  lua_call(L, 1, 0);

  lua_pushcfunction(L, luaopen_table);
  lua_pushstring(L, 'table');
  lua_call(L, 1, 0);

  // and so on..

  luaL_loadfile(L, ...);

linit.c also declares this function (translated from C):

const lualibs: array[0..7] of luaL_Reg = (
    (Name: ''; Func: luaopen_base),
    (Name: LUA_LOADLIBNAME; Func: luaopen_package),
    (Name: LUA_TABLIBNAME; Func: luaopen_table),
    (Name: LUA_IOLIBNAME; Func: luaopen_io),
    (Name: LUA_OSLIBNAME; Func: luaopen_os),
    (Name: LUA_STRLIBNAME; Func: luaopen_string),
    (Name: LUA_MATHLIBNAME; Func: luaopen_math),
    (Name: LUA_DBLIBNAME; Func: luaopen_debug)

procedure luaL_openlibs(L: Plua_State);
  i: Integer;
  for i:= Low(lualibs) to High(lualibs) do
    lua_pushcfunction(L, lualibs[i].func);
    lua_pushstring(L, lualibs[i].name);
    lua_call(L, 1, 0);

(No need to say that I haven't tested this code, right?)

I also don't know if luapas.pas implements the 5.1 Lua API, perhaps you'll be more lucky contacting the author.