uses
  lua;

var
  I: LongInt = 3;

function Func(L: Plua_State): LongInt; cdecl;
begin
  lua_pushinteger(L, I);
  Inc(I);
  Exit(1);
end;

var
  L: Plua_State;
  P: Plua_Number;

procedure DoStep;
begin
  if luaL_loadstring(L, 'return Func();') <> LUA_OK then begin
    Writeln(stderr, 'Failed compiling lua script');
    Halt(1);
  end;
  lua_pcall(L, 0, LUA_MULTRET, 0);
  Writeln(lua_tointeger(L, 0));
end;

begin
  Writeln(PtrUInt(@lua_version));
  P := lua_version(nil);
  Writeln(P^);
  L := luaL_newstate;
  lua_register(L, 'Func', @Func);
  DoStep;
  DoStep;
  DoStep;
  DoStep;
  DoStep;
  DoStep;
  DoStep;
  DoStep;
  lua_close(L);
end.
