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.

[1] http://www.lua.org/manual/5.1/manual.html#7.3

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

begin
  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, ...);
  ...
end;


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);
var
  i: Integer;
begin
  for i:= Low(lualibs) to High(lualibs) do
  begin
    lua_pushcfunction(L, lualibs[i].func);
    lua_pushstring(L, lualibs[i].name);
    lua_call(L, 1, 0);
  end;
end;

(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.

--rb