--- a/hedgewars/LuaPas.pas Mon Jan 16 10:22:21 2012 +0100
+++ b/hedgewars/LuaPas.pas Tue Jan 17 09:01:31 2012 -0500
@@ -15,12 +15,12 @@
{$INCLUDE "config.inc"}
type
- size_t = Cardinal;
- Psize_t = ^size_t;
- PPointer = ^Pointer;
+ size_t = Cardinal;
+ Psize_t = ^size_t;
+ PPointer = ^Pointer;
- lua_State = record end;
- Plua_State = ^lua_State;
+ lua_State = record end;
+ Plua_State = ^lua_State;
const
LuaLibName = cLuaLibrary;
@@ -45,8 +45,8 @@
** ===================================================================
*)
type
- LUA_NUMBER_ = Double; // ending underscore is needed in Pascal
- LUA_INTEGER_ = PtrInt;
+ LUA_NUMBER_ = Double; // ending underscore is needed in Pascal
+ LUA_INTEGER_ = PtrInt;
(*
@@ LUA_IDSIZE gives the maximum size for the description of the source
@@ -54,13 +54,13 @@
** CHANGE it if you want a different size.
*)
const
- LUA_IDSIZE = 60;
+ LUA_IDSIZE = 60;
(*
@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
*)
const
- LUAL_BUFFERSIZE = 1024;
+ LUAL_BUFFERSIZE = 1024;
(*
@@ LUA_PROMPT is the default prompt used by stand-alone Lua.
@@ -69,8 +69,8 @@
** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.)
*)
const
- LUA_PROMPT = '> ';
- LUA_PROMPT2 = '>> ';
+ LUA_PROMPT = '> ';
+ LUA_PROMPT2 = '>> ';
(*
@@ lua_readline defines how to show a prompt and then read a line from
@@ -80,8 +80,11 @@
** CHANGE them if you want to improve this functionality (e.g., by using
** GNU readline and history facilities).
*)
-function lua_readline(L : Plua_State; var b : PChar; p : PChar): Boolean;
+function lua_readline(L : Plua_State;
+var b : PChar; p : PChar): Boolean;
+
procedure lua_saveline(L : Plua_State; idx : LongInt);
+
procedure lua_freeline(L : Plua_State; b : PChar);
(*
@@ -95,7 +98,7 @@
#define lua_stdin_is_tty() _isatty(_fileno(stdin))
*)
const
- lua_stdin_is_tty = TRUE;
+ lua_stdin_is_tty = TRUE;
(*****************************************************************************)
(* lua.h *)
@@ -109,283 +112,329 @@
*)
const
- LUA_VERSION = 'Lua 5.1';
- LUA_VERSION_NUM = 501;
- LUA_COPYRIGHT = 'Copyright (C) 1994-2006 Tecgraf, PUC-Rio';
- LUA_AUTHORS = 'R. Ierusalimschy, L. H. de Figueiredo & W. Celes';
+ LUA_VERSION = 'Lua 5.1';
+ LUA_VERSION_NUM = 501;
+ LUA_COPYRIGHT = 'Copyright (C) 1994-2006 Tecgraf, PUC-Rio';
+ LUA_AUTHORS = 'R. Ierusalimschy, L. H. de Figueiredo & W. Celes';
- (* mark for precompiled code (`<esc>Lua') *)
- LUA_SIGNATURE = #27 + 'Lua';
+ (* mark for precompiled code (`<esc>Lua') *)
+ LUA_SIGNATURE = #27 + 'Lua';
- (* option for multiple returns in `lua_pcall' and `lua_call' *)
- LUA_MULTRET = -1;
+ (* option for multiple returns in `lua_pcall' and `lua_call' *)
+ LUA_MULTRET = -1;
- (*
- ** pseudo-indices
- *)
- LUA_REGISTRYINDEX = -10000;
- LUA_ENVIRONINDEX = -10001;
- LUA_GLOBALSINDEX = -10002;
+ (*
+ ** pseudo-indices
+ *)
+ LUA_REGISTRYINDEX = -10000;
+ LUA_ENVIRONINDEX = -10001;
+ LUA_GLOBALSINDEX = -10002;
function lua_upvalueindex(idx : LongInt) : LongInt; // a marco
const
- (* thread status; 0 is OK *)
- LUA_YIELD_ = 1; // Note: the ending underscore is needed in Pascal
- LUA_ERRRUN = 2;
- LUA_ERRSYNTAX = 3;
- LUA_ERRMEM = 4;
- LUA_ERRERR = 5;
+ (* thread status; 0 is OK *)
+ LUA_YIELD_ = 1; // Note: the ending underscore is needed in Pascal
+ LUA_ERRRUN = 2;
+ LUA_ERRSYNTAX = 3;
+ LUA_ERRMEM = 4;
+ LUA_ERRERR = 5;
type
- lua_CFunction = function(L : Plua_State) : LongInt; cdecl;
+ lua_CFunction = function(L : Plua_State) : LongInt; cdecl;
- (*
- ** functions that read/write blocks when loading/dumping Lua chunks
- *)
- lua_Reader = function (L : Plua_State; ud : Pointer;
- sz : Psize_t) : PChar; cdecl;
- lua_Writer = function (L : Plua_State; const p : Pointer; sz : size_t;
- ud : Pointer) : LongInt; cdecl;
+ (*
+ ** functions that read/write blocks when loading/dumping Lua chunks
+ *)
+ lua_Reader = function (L : Plua_State; ud : Pointer; sz : Psize_t) : PChar; cdecl;
+ lua_Writer = function (L : Plua_State; const p : Pointer; sz : size_t; ud : Pointer) : LongInt; cdecl;
(*
** prototype for memory-allocation functions
*)
- lua_Alloc = function (ud, ptr : Pointer;
- osize, nsize : size_t) : Pointer; cdecl;
+ lua_Alloc = function (ud, ptr : Pointer; osize, nsize : size_t) : Pointer; cdecl;
const
- (*
- ** basic types
- *)
- LUA_TNONE = -1;
+ (*
+ ** basic types
+ *)
+ LUA_TNONE = -1;
+ LUA_TNIL = 0;
+ LUA_TBOOLEAN = 1;
+ LUA_TLIGHTUSERDATA = 2;
+ LUA_TNUMBER = 3;
+ LUA_TSTRING = 4;
+ LUA_TTABLE = 5;
+ LUA_TFUNCTION = 6;
+ LUA_TUSERDATA = 7;
+ LUA_TTHREAD = 8;
- LUA_TNIL = 0;
- LUA_TBOOLEAN = 1;
- LUA_TLIGHTUSERDATA = 2;
- LUA_TNUMBER = 3;
- LUA_TSTRING = 4;
- LUA_TTABLE = 5;
- LUA_TFUNCTION = 6;
- LUA_TUSERDATA = 7;
- LUA_TTHREAD = 8;
-
- (* minimum Lua stack available to a C function *)
- LUA_MINSTACK = 20;
+ (* minimum Lua stack available to a C function *)
+ LUA_MINSTACK = 20;
type
- (* type of numbers in Lua *)
- lua_Number = LUA_NUMBER_;
+ (* type of numbers in Lua *)
+ lua_Number = LUA_NUMBER_;
- (* type for integer functions *)
- lua_Integer = LUA_INTEGER_;
+ (* type for integer functions *)
+ lua_Integer = LUA_INTEGER_;
(*
** state manipulation
*)
function lua_newstate(f : lua_Alloc; ud : Pointer) : Plua_State;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
procedure lua_close(L: Plua_State);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
function lua_newthread(L : Plua_State) : Plua_State;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
function lua_atpanic(L : Plua_State; panicf : lua_CFunction) : lua_CFunction;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
(*
** basic stack manipulation
*)
function lua_gettop(L : Plua_State) : LongInt;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
procedure lua_settop(L : Plua_State; idx : LongInt);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
procedure lua_pushvalue(L : Plua_State; idx : LongInt);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
procedure lua_remove(L : Plua_State; idx : LongInt);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
procedure lua_insert(L : Plua_State; idx : LongInt);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
procedure lua_replace(L : Plua_State; idx : LongInt);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
function lua_checkstack(L : Plua_State; sz : LongInt) : LongBool;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
procedure lua_xmove(src, dest : Plua_State; n : LongInt);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
(*
** access functions (stack -> C)
*)
function lua_isnumber(L : Plua_State; idx : LongInt) : LongBool;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
function lua_isstring(L : Plua_State; idx : LongInt) : LongBool;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
function lua_iscfunction(L : Plua_State; idx : LongInt) : LongBool;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
function lua_isuserdata(L : Plua_State; idx : LongInt) : LongBool;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
function lua_type(L : Plua_State; idx : LongInt) : LongInt;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
function lua_typename(L : Plua_State; tp : LongInt) : PChar;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
function lua_equal(L : Plua_State; idx1, idx2 : LongInt) : LongBool;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
function lua_rawequal(L : Plua_State; idx1, idx2 : LongInt) : LongBool;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
function lua_lessthan(L : Plua_State; idx1, idx2 : LongInt) : LongBool;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
function lua_tonumber(L : Plua_State; idx : LongInt) : lua_Number;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
function lua_tointeger(L : Plua_State; idx : LongInt) : lua_Integer;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
function lua_toboolean(L : Plua_State; idx : LongInt) : LongBool;
- cdecl; external LuaLibName;
-function lua_tolstring(L : Plua_State; idx : LongInt;
- len : Psize_t) : PChar;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
+
+function lua_tolstring(L : Plua_State; idx : LongInt; len : Psize_t) : PChar;
+ cdecl; external LuaLibName;
+
function lua_objlen(L : Plua_State; idx : LongInt) : size_t;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
function lua_tocfunction(L : Plua_State; idx : LongInt) : lua_CFunction;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
function lua_touserdata(L : Plua_State; idx : LongInt) : Pointer;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
function lua_tothread(L : Plua_State; idx : LongInt) : Plua_State;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
function lua_topointer(L : Plua_State; idx : LongInt) : Pointer;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
(*
** push functions (C -> stack)
*)
procedure lua_pushnil(L : Plua_State);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
procedure lua_pushnumber(L : Plua_State; n : lua_Number);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
procedure lua_pushinteger(L : Plua_State; n : lua_Integer);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
procedure lua_pushlstring(L : Plua_State; const s : PChar; ls : size_t);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
procedure lua_pushstring(L : Plua_State; const s : PChar);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
+
function lua_pushvfstring(L : Plua_State;
- const fmt : PChar; argp : Pointer) : PChar;
- cdecl; external LuaLibName;
+ const fmt : PChar; argp : Pointer) : PChar;
+ cdecl; external LuaLibName;
+
function lua_pushfstring(L : Plua_State; const fmt : PChar) : PChar; varargs;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
procedure lua_pushcclosure(L : Plua_State; fn : lua_CFunction; n : LongInt);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
procedure lua_pushboolean(L : Plua_State; b : LongBool);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
procedure lua_pushlightuserdata(L : Plua_State; p : Pointer);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
function lua_pushthread(L : Plua_state) : Cardinal;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
(*
** get functions (Lua -> stack)
*)
procedure lua_gettable(L : Plua_State ; idx : LongInt);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
procedure lua_getfield(L : Plua_State; idx : LongInt; k : PChar);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
procedure lua_rawget(L : Plua_State; idx : LongInt);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
procedure lua_rawgeti(L : Plua_State; idx, n : LongInt);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
procedure lua_createtable(L : Plua_State; narr, nrec : LongInt);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
function lua_newuserdata(L : Plua_State; sz : size_t) : Pointer;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
function lua_getmetatable(L : Plua_State; objindex : LongInt) : LongBool;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
procedure lua_getfenv(L : Plua_State; idx : LongInt);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
(*
** set functions (stack -> Lua)
*)
procedure lua_settable(L : Plua_State; idx : LongInt);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
procedure lua_setfield(L : Plua_State; idx : LongInt; const k : PChar);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
procedure lua_rawset(L : Plua_State; idx : LongInt);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
procedure lua_rawseti(L : Plua_State; idx , n: LongInt);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
function lua_setmetatable(L : Plua_State; objindex : LongInt): LongBool;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
function lua_setfenv(L : Plua_State; idx : LongInt): LongBool;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
(*
** `load' and `call' functions (load and run Lua code)
*)
procedure lua_call(L : Plua_State; nargs, nresults : LongInt);
- cdecl; external LuaLibName;
-function lua_pcall(L : Plua_State;
- nargs, nresults, errfunc : LongInt) : LongInt;
- cdecl; external LuaLibName;
-function lua_cpcall(L : Plua_State;
- func : lua_CFunction; ud : Pointer) : LongInt;
- cdecl; external LuaLibName;
-function lua_load(L : Plua_State; reader : lua_Reader;
- dt : Pointer; const chunkname : PChar) : LongInt;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
+function lua_pcall(L : Plua_State; nargs, nresults, errfunc : LongInt) : LongInt;
+ cdecl; external LuaLibName;
+
+function lua_cpcall(L : Plua_State; func : lua_CFunction; ud : Pointer) : LongInt;
+ cdecl; external LuaLibName;
+
+function lua_load(L : Plua_State; reader : lua_Reader; dt : Pointer; const chunkname : PChar) : LongInt;
+ cdecl; external LuaLibName;
+
function lua_dump(L : Plua_State; writer : lua_Writer; data: Pointer) : LongInt;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
(*
** coroutine functions
*)
function lua_yield(L : Plua_State; nresults : LongInt) : LongInt;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
function lua_resume(L : Plua_State; narg : LongInt) : LongInt;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
function lua_status(L : Plua_State) : LongInt;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
(*
** garbage-collection functions and options
*)
const
- LUA_GCSTOP = 0;
- LUA_GCRESTART = 1;
- LUA_GCCOLLECT = 2;
- LUA_GCCOUNT = 3;
- LUA_GCCOUNTB = 4;
- LUA_GCSTEP = 5;
- LUA_GCSETPAUSE = 6;
- LUA_GCSETSTEPMUL = 7;
+ LUA_GCSTOP = 0;
+ LUA_GCRESTART = 1;
+ LUA_GCCOLLECT = 2;
+ LUA_GCCOUNT = 3;
+ LUA_GCCOUNTB = 4;
+ LUA_GCSTEP = 5;
+ LUA_GCSETPAUSE = 6;
+ LUA_GCSETSTEPMUL = 7;
function lua_gc(L : Plua_State; what, data : LongInt) : LongInt;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
(*
** miscellaneous functions
*)
function lua_error(L : Plua_State) : LongInt;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
function lua_next(L : Plua_State; idx : LongInt) : LongInt;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
procedure lua_concat(L : Plua_State; n : LongInt);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
function lua_getallocf(L : Plua_State; ud : PPointer) : lua_Alloc;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
procedure lua_setallocf(L : Plua_State; f : lua_Alloc; ud : Pointer);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
(*
** ===============================================================
@@ -429,8 +478,8 @@
function lua_getgccount(L : Plua_State) : LongInt;
type
- lua_Chuckreader = lua_Reader;
- lua_Chuckwriter = lua_Writer;
+ lua_Chuckreader = lua_Reader;
+ lua_Chuckwriter = lua_Writer;
(* ====================================================================== *)
@@ -444,23 +493,23 @@
** Event codes
*)
const
- LUA_HOOKCALL = 0;
- LUA_HOOKRET = 1;
- LUA_HOOKLINE = 2;
- LUA_HOOKCOUNT = 3;
- LUA_HOOKTAILRET = 4;
+ LUA_HOOKCALL = 0;
+ LUA_HOOKRET = 1;
+ LUA_HOOKLINE = 2;
+ LUA_HOOKCOUNT = 3;
+ LUA_HOOKTAILRET = 4;
(*
** Event masks
*)
- LUA_MASKCALL = 1 shl LUA_HOOKCALL;
- LUA_MASKRET = 1 shl LUA_HOOKRET;
- LUA_MASKLINE = 1 shl LUA_HOOKLINE;
- LUA_MASKCOUNT = 1 shl LUA_HOOKCOUNT;
+ LUA_MASKCALL = 1 shl LUA_HOOKCALL;
+ LUA_MASKRET = 1 shl LUA_HOOKRET;
+ LUA_MASKLINE = 1 shl LUA_HOOKLINE;
+ LUA_MASKCOUNT = 1 shl LUA_HOOKCOUNT;
type
- lua_Debug = packed record
+ lua_Debug = packed record
event : LongInt;
name : PChar; (* (n) *)
namewhat : PChar; (* (n) `global', `local', `field', `method' *)
@@ -472,42 +521,44 @@
short_src : array [0..LUA_IDSIZE-1] of Char; (* (S) *)
(* private part *)
i_ci : LongInt; (* active function *)
- end;
- Plua_Debug = ^lua_Debug;
+ end;
+ Plua_Debug = ^lua_Debug;
(* Functions to be called by the debuger in specific events *)
lua_Hook = procedure (L : Plua_State; ar : Plua_Debug); cdecl;
-function lua_getstack(L : Plua_State; level : LongInt;
- ar : Plua_Debug) : LongInt;
- cdecl; external LuaLibName;
-function lua_getinfo(L : Plua_State; const what : PChar;
- ar: Plua_Debug): LongInt;
- cdecl; external LuaLibName;
-function lua_getlocal(L : Plua_State;
- ar : Plua_Debug; n : LongInt) : PChar;
- cdecl; external LuaLibName;
-function lua_setlocal(L : Plua_State;
- ar : Plua_Debug; n : LongInt) : PChar;
- cdecl; external LuaLibName;
+function lua_getstack(L : Plua_State; level : LongInt; ar : Plua_Debug) : LongInt;
+ cdecl; external LuaLibName;
+
+function lua_getinfo(L : Plua_State; const what : PChar; ar: Plua_Debug): LongInt;
+ cdecl; external LuaLibName;
+
+function lua_getlocal(L : Plua_State; ar : Plua_Debug; n : LongInt) : PChar;
+ cdecl; external LuaLibName;
+
+function lua_setlocal(L : Plua_State; ar : Plua_Debug; n : LongInt) : PChar;
+ cdecl; external LuaLibName;
+
function lua_getupvalue(L : Plua_State; funcindex, n : LongInt) : PChar;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
function lua_setupvalue(L : Plua_State; funcindex, n : LongInt) : PChar;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
-function lua_sethook(L : Plua_State; func : lua_Hook;
- mask, count: LongInt): LongInt;
- cdecl; external LuaLibName;
+function lua_sethook(L : Plua_State; func : lua_Hook; mask, count: LongInt): LongInt;
+ cdecl; external LuaLibName;
+
{$IFDEF LUA_GETHOOK}
function lua_gethook(L : Plua_State) : lua_Hook;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
{$ENDIF}
function lua_gethookmask(L : Plua_State) : LongInt;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+
function lua_gethookcount(L : Plua_State) : LongInt;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
(*****************************************************************************)
@@ -521,44 +572,44 @@
*)
const
- (* Key to file-handle type *)
- LUA_FILEHANDLE = 'FILE*';
+ (* Key to file-handle type *)
+ LUA_FILEHANDLE = 'FILE*';
- LUA_COLIBNAME = 'coroutine';
- LUA_TABLIBNAME = 'table';
- LUA_IOLIBNAME = 'io';
- LUA_OSLIBNAME = 'os';
- LUA_STRLIBNAME = 'string';
- LUA_MATHLIBNAME = 'math';
- LUA_DBLIBNAME = 'debug';
- LUA_LOADLIBNAME = 'package';
+ LUA_COLIBNAME = 'coroutine';
+ LUA_TABLIBNAME = 'table';
+ LUA_IOLIBNAME = 'io';
+ LUA_OSLIBNAME = 'os';
+ LUA_STRLIBNAME = 'string';
+ LUA_MATHLIBNAME = 'math';
+ LUA_DBLIBNAME = 'debug';
+ LUA_LOADLIBNAME = 'package';
function luaopen_base(L : Plua_State) : LongInt;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
function luaopen_table(L : Plua_State) : LongInt;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
function luaopen_io(L : Plua_State) : LongInt;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
function luaopen_os(L : Plua_State) : LongInt;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
function luaopen_string(L : Plua_State) : LongInt;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
function luaopen_math(L : Plua_State) : LongInt;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
function luaopen_debug(L : Plua_State) : LongInt;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
function luaopen_package(L : Plua_State) : LongInt;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
procedure luaL_openlibs(L : Plua_State);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
procedure lua_assert(x : Boolean); // a macro
@@ -578,97 +629,83 @@
procedure luaL_setn(L : Plua_State; i, j : LongInt);
const
- LUA_ERRFILE = LUA_ERRERR + 1;
+ LUA_ERRFILE = LUA_ERRERR + 1;
type
- luaL_Reg = packed record
+ luaL_Reg = packed record
name : PChar;
func : lua_CFunction;
- end;
- PluaL_Reg = ^luaL_Reg;
+ end;
+ PluaL_Reg = ^luaL_Reg;
-procedure luaL_openlib(L : Plua_State; const libname : PChar;
- const lr : PluaL_Reg; nup : LongInt);
- cdecl; external LuaLibName;
-procedure luaL_register(L : Plua_State; const libname : PChar;
- const lr : PluaL_Reg);
- cdecl; external LuaLibName;
-function luaL_getmetafield(L : Plua_State; obj : LongInt;
- const e : PChar) : LongInt;
- cdecl; external LuaLibName;
-function luaL_callmeta(L : Plua_State; obj : LongInt;
- const e : PChar) : LongInt;
- cdecl; external LuaLibName;
-function luaL_typerror(L : Plua_State; narg : LongInt;
- const tname : PChar) : LongInt;
- cdecl; external LuaLibName;
-function luaL_argerror(L : Plua_State; numarg : LongInt;
- const extramsg : PChar) : LongInt;
- cdecl; external LuaLibName;
-function luaL_checklstring(L : Plua_State; numArg : LongInt;
- ls : Psize_t) : PChar;
- cdecl; external LuaLibName;
-function luaL_optlstring(L : Plua_State; numArg : LongInt;
- const def: PChar; ls: Psize_t) : PChar;
- cdecl; external LuaLibName;
+procedure luaL_openlib(L : Plua_State; const libname : PChar; const lr : PluaL_Reg; nup : LongInt);
+ cdecl; external LuaLibName;
+procedure luaL_register(L : Plua_State; const libname : PChar; const lr : PluaL_Reg);
+ cdecl; external LuaLibName;
+function luaL_getmetafield(L : Plua_State; obj : LongInt; const e : PChar) : LongInt;
+ cdecl; external LuaLibName;
+function luaL_callmeta(L : Plua_State; obj : LongInt; const e : PChar) : LongInt;
+ cdecl; external LuaLibName;
+function luaL_typerror(L : Plua_State; narg : LongInt; const tname : PChar) : LongInt;
+ cdecl; external LuaLibName;
+function luaL_argerror(L : Plua_State; numarg : LongInt; const extramsg : PChar) : LongInt;
+ cdecl; external LuaLibName;
+function luaL_checklstring(L : Plua_State; numArg : LongInt; ls : Psize_t) : PChar;
+ cdecl; external LuaLibName;
+function luaL_optlstring(L : Plua_State; numArg : LongInt; const def: PChar; ls: Psize_t) : PChar;
+ cdecl; external LuaLibName;
function luaL_checknumber(L : Plua_State; numArg : LongInt) : lua_Number;
- cdecl; external LuaLibName;
-function luaL_optnumber(L : Plua_State; nArg : LongInt;
- def : lua_Number) : lua_Number;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+function luaL_optnumber(L : Plua_State; nArg : LongInt; def : lua_Number) : lua_Number;
+ cdecl; external LuaLibName;
function luaL_checkinteger(L : Plua_State; numArg : LongInt) : lua_Integer;
- cdecl; external LuaLibName;
-function luaL_optinteger(L : Plua_State; nArg : LongInt;
- def : lua_Integer) : lua_Integer;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+function luaL_optinteger(L : Plua_State; nArg : LongInt; def : lua_Integer) : lua_Integer;
+ cdecl; external LuaLibName;
procedure luaL_checkstack(L : Plua_State; sz : LongInt; const msg : PChar);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
procedure luaL_checktype(L : Plua_State; narg, t : LongInt);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
procedure luaL_checkany(L : Plua_State; narg : LongInt);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
function luaL_newmetatable(L : Plua_State; const tname : PChar) : LongInt;
- cdecl; external LuaLibName;
-function luaL_checkudata(L : Plua_State; ud : LongInt;
- const tname : PChar) : Pointer;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+function luaL_checkudata(L : Plua_State; ud : LongInt; const tname : PChar) : Pointer;
+ cdecl; external LuaLibName;
procedure luaL_where(L : Plua_State; lvl : LongInt);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
function luaL_error(L : Plua_State; const fmt : PChar) : LongInt; varargs;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
-function luaL_checkoption(L : Plua_State; narg : LongInt; const def : PChar;
- const lst : array of PChar) : LongInt;
- cdecl; external LuaLibName;
+function luaL_checkoption(L : Plua_State; narg : LongInt; const def : PChar; const lst : array of PChar) : LongInt;
+ cdecl; external LuaLibName;
function luaL_ref(L : Plua_State; t : LongInt) : LongInt;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
procedure luaL_unref(L : Plua_State; t, ref : LongInt);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
function luaL_loadfile(L : Plua_State; const filename : PChar) : LongInt;
- cdecl; external LuaLibName;
-function luaL_loadbuffer(L : Plua_State; const buff : PChar;
- sz : size_t; const name: PChar) : LongInt;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
+function luaL_loadbuffer(L : Plua_State; const buff : PChar; sz : size_t; const name: PChar) : LongInt;
+ cdecl; external LuaLibName;
function luaL_loadstring(L : Plua_State; const s : Pchar) : LongInt;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
function luaL_newstate : Plua_State;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
function luaL_gsub(L : Plua_State; const s, p, r : PChar) : PChar;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
-function luaL_findtable(L : Plua_State; idx : LongInt;
- const fname : PChar; szhint : LongInt) : PChar;
- cdecl; external LuaLibName;
+function luaL_findtable(L : Plua_State; idx : LongInt; const fname : PChar; szhint : LongInt) : PChar;
+ cdecl; external LuaLibName;
(*
@@ -677,8 +714,7 @@
** ===============================================================
*)
-function luaL_argcheck(L : Plua_State; cond : Boolean; numarg : LongInt;
- extramsg : PChar): LongInt;
+function luaL_argcheck(L : Plua_State; cond : Boolean; numarg : LongInt; extramsg : PChar): LongInt;
function luaL_checkstring(L : Plua_State; n : LongInt) : PChar;
function luaL_optstring(L : Plua_State; n : LongInt; d : PChar) : PChar;
function luaL_checkint(L : Plua_State; n : LongInt) : lua_Integer;
@@ -705,13 +741,13 @@
*)
type
- luaL_Buffer = packed record
+ luaL_Buffer = packed record
p : PChar; (* current position in buffer *)
lvl : LongInt; (* number of strings in the stack (level) *)
L : Plua_State;
buffer : array [0..LUAL_BUFFERSIZE-1] of Char;
- end;
- PluaL_Buffer = ^luaL_Buffer;
+ end;
+ PluaL_Buffer = ^luaL_Buffer;
procedure luaL_addchar(B : PluaL_Buffer; c : Char);
@@ -721,17 +757,17 @@
procedure luaL_addsize(B : PluaL_Buffer; n : LongInt);
procedure luaL_buffinit(L : Plua_State; B : PluaL_Buffer);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
function luaL_prepbuffer(B : PluaL_Buffer) : PChar;
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
procedure luaL_addlstring(B : PluaL_Buffer; const s : PChar; ls : size_t);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
procedure luaL_addstring(B : PluaL_Buffer; const s : PChar);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
procedure luaL_addvalue(B : PluaL_Buffer);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
procedure luaL_pushresult(B : PluaL_Buffer);
- cdecl; external LuaLibName;
+ cdecl; external LuaLibName;
(* ====================================================== *)
@@ -740,8 +776,8 @@
(* pre-defined references *)
const
- LUA_NOREF = -2;
- LUA_REFNIL = -1;
+ LUA_NOREF = -2;
+ LUA_REFNIL = -1;
function lua_ref(L : Plua_State; lock : Boolean) : LongInt;
@@ -763,14 +799,16 @@
(* luaconfig.h *)
(*****************************************************************************)
-function lua_readline(L : Plua_State; var b : PChar; p : PChar): Boolean;
+function lua_readline(L : Plua_State;
var
- s : AnsiString;
+ b : PChar; p : PChar): Boolean;
+var
+ s : AnsiString;
begin
- Write(p); // show prompt
- ReadLn(s); // get line
- b := PChar(s); // and return it
- lua_readline := (b[0] <> #4); // test for ctrl-D
+ Write(p); // show prompt
+ ReadLn(s); // get line
+ b := PChar(s); // and return it
+ lua_readline := (b[0] <> #4); // test for ctrl-D
end;
procedure lua_saveline(L : Plua_State; idx : LongInt);
@@ -788,108 +826,108 @@
function lua_upvalueindex(idx : LongInt) : LongInt;
begin
- lua_upvalueindex := LUA_GLOBALSINDEX - idx;
+lua_upvalueindex := LUA_GLOBALSINDEX - idx;
end;
procedure lua_pop(L : Plua_State; n : LongInt);
begin
- lua_settop(L, -n - 1);
+lua_settop(L, -n - 1);
end;
procedure lua_newtable(L : Plua_State);
begin
- lua_createtable(L, 0, 0);
+lua_createtable(L, 0, 0);
end;
procedure lua_register(L : Plua_State; n : PChar; f : lua_CFunction);
begin
- lua_pushcfunction(L, f);
- lua_setglobal(L, n);
+lua_pushcfunction(L, f);
+lua_setglobal(L, n);
end;
procedure lua_pushcfunction(L : Plua_State; f : lua_CFunction);
begin
- lua_pushcclosure(L, f, 0);
+ lua_pushcclosure(L, f, 0);
end;
function lua_strlen(L : Plua_State; idx : LongInt) : LongInt;
begin
- lua_strlen := lua_objlen(L, idx);
+ lua_strlen := lua_objlen(L, idx);
end;
function lua_isfunction(L : Plua_State; n : LongInt) : Boolean;
begin
- lua_isfunction := lua_type(L, n) = LUA_TFUNCTION;
+ lua_isfunction := lua_type(L, n) = LUA_TFUNCTION;
end;
function lua_istable(L : Plua_State; n : LongInt) : Boolean;
begin
- lua_istable := lua_type(L, n) = LUA_TTABLE;
+ lua_istable := lua_type(L, n) = LUA_TTABLE;
end;
function lua_islightuserdata(L : Plua_State; n : LongInt) : Boolean;
begin
- lua_islightuserdata := lua_type(L, n) = LUA_TLIGHTUSERDATA;
+ lua_islightuserdata := lua_type(L, n) = LUA_TLIGHTUSERDATA;
end;
function lua_isnil(L : Plua_State; n : LongInt) : Boolean;
begin
- lua_isnil := lua_type(L, n) = LUA_TNIL;
+ lua_isnil := lua_type(L, n) = LUA_TNIL;
end;
function lua_isboolean(L : Plua_State; n : LongInt) : Boolean;
begin
- lua_isboolean := lua_type(L, n) = LUA_TBOOLEAN;
+ lua_isboolean := lua_type(L, n) = LUA_TBOOLEAN;
end;
function lua_isthread(L : Plua_State; n : LongInt) : Boolean;
begin
- lua_isthread := lua_type(L, n) = LUA_TTHREAD;
+ lua_isthread := lua_type(L, n) = LUA_TTHREAD;
end;
function lua_isnone(L : Plua_State; n : LongInt) : Boolean;
begin
- lua_isnone := lua_type(L, n) = LUA_TNONE;
+ lua_isnone := lua_type(L, n) = LUA_TNONE;
end;
function lua_isnoneornil(L : Plua_State; n : LongInt) : Boolean;
begin
- lua_isnoneornil := lua_type(L, n) <= 0;
+ lua_isnoneornil := lua_type(L, n) <= 0;
end;
procedure lua_pushliteral(L : Plua_State; s : PChar);
begin
- lua_pushlstring(L, s, StrLen(s));
+ lua_pushlstring(L, s, StrLen(s));
end;
procedure lua_setglobal(L : Plua_State; s : PChar);
begin
- lua_setfield(L, LUA_GLOBALSINDEX, s);
+ lua_setfield(L, LUA_GLOBALSINDEX, s);
end;
procedure lua_getglobal(L: Plua_State; s: PChar);
begin
- lua_getfield(L, LUA_GLOBALSINDEX, s);
+ lua_getfield(L, LUA_GLOBALSINDEX, s);
end;
function lua_tostring(L : Plua_State; idx : LongInt) : AnsiString;
begin
- lua_tostring := SysUtils.StrPas(lua_tolstring(L, idx, nil));
+ lua_tostring := SysUtils.StrPas(lua_tolstring(L, idx, nil));
end;
function lua_open : Plua_State;
begin
- lua_open := luaL_newstate;
+ lua_open := luaL_newstate;
end;
procedure lua_getregistry(L : Plua_State);
begin
- lua_pushvalue(L, LUA_REGISTRYINDEX);
+ lua_pushvalue(L, LUA_REGISTRYINDEX);
end;
function lua_getgccount(L : Plua_State) : LongInt;
begin
- lua_getgccount := lua_gc(L, LUA_GCCOUNT, 0);
+ lua_getgccount := lua_gc(L, LUA_GCCOUNT, 0);
end;
@@ -908,88 +946,87 @@
function luaL_getn(L : Plua_State; idx : LongInt) : LongInt;
begin
- luaL_getn := lua_objlen(L, idx);
+ luaL_getn := lua_objlen(L, idx);
end;
procedure luaL_setn(L : plua_State; i, j : LongInt);
begin
- (* no op *)
+ (* no op *)
end;
-function luaL_argcheck(L : Plua_State; cond : Boolean; numarg : LongInt;
- extramsg : PChar): LongInt;
+function luaL_argcheck(L : Plua_State; cond : Boolean; numarg : LongInt; extramsg : PChar): LongInt;
begin
- if not cond then
- luaL_argcheck := luaL_argerror(L, numarg, extramsg)
- else
- luaL_argcheck := 0;
+ if not cond then
+ luaL_argcheck := luaL_argerror(L, numarg, extramsg)
+ else
+ luaL_argcheck := 0;
end;
function luaL_checkstring(L : Plua_State; n : LongInt) : PChar;
begin
- luaL_checkstring := luaL_checklstring(L, n, nil);
+ luaL_checkstring := luaL_checklstring(L, n, nil);
end;
function luaL_optstring(L : Plua_State; n : LongInt; d : PChar) : PChar;
begin
- luaL_optstring := luaL_optlstring(L, n, d, nil);
+ luaL_optstring := luaL_optlstring(L, n, d, nil);
end;
function luaL_checkint(L : Plua_State; n : LongInt) : lua_Integer;
begin
- luaL_checkint := luaL_checkinteger(L, n);
+ luaL_checkint := luaL_checkinteger(L, n);
end;
function luaL_optint(L : Plua_State; n : LongInt; d : lua_Integer): lua_Integer;
begin
- luaL_optint := luaL_optinteger(L, n, d);
+ luaL_optint := luaL_optinteger(L, n, d);
end;
function luaL_checklong(L : Plua_State; n : LongInt) : lua_Integer;
begin
- luaL_checklong := luaL_checkinteger(L, n);
+ luaL_checklong := luaL_checkinteger(L, n);
end;
function luaL_optlong(L : Plua_State; n : LongInt; d : lua_Integer) : lua_Integer;
begin
- luaL_optlong := luaL_optinteger(L, n, d);
+ luaL_optlong := luaL_optinteger(L, n, d);
end;
function luaL_typename(L : Plua_State; idx : LongInt) : PChar;
begin
- luaL_typename := lua_typename( L, lua_type(L, idx) );
+ luaL_typename := lua_typename( L, lua_type(L, idx) );
end;
function luaL_dofile(L : Plua_State; fn : PChar) : LongInt;
begin
- luaL_dofile := luaL_loadfile(L, fn);
- if luaL_dofile = 0 then
- luaL_dofile := lua_pcall(L, 0, 0, 0);
+ luaL_dofile := luaL_loadfile(L, fn);
+ if luaL_dofile = 0 then
+ luaL_dofile := lua_pcall(L, 0, 0, 0);
end;
function luaL_dostring(L : Plua_State; s : PChar) : LongInt;
begin
- luaL_dostring := luaL_loadstring(L, s);
- if luaL_dostring = 0 then
- luaL_dostring := lua_pcall(L, 0, 0, 0);
+ luaL_dostring := luaL_loadstring(L, s);
+ if luaL_dostring = 0 then
+ luaL_dostring := lua_pcall(L, 0, 0, 0);
end;
procedure luaL_getmetatable(L : Plua_State; n : PChar);
begin
- lua_getfield(L, LUA_REGISTRYINDEX, n);
+ lua_getfield(L, LUA_REGISTRYINDEX, n);
end;
procedure luaL_addchar(B : PluaL_Buffer; c : Char);
begin
- if not(B^.p < B^.buffer + LUAL_BUFFERSIZE) then
- luaL_prepbuffer(B);
- (B^.p^) := c;
- Inc(B^.p);
+ if not(B^.p < B^.buffer + LUAL_BUFFERSIZE) then
+ luaL_prepbuffer(B);
+ (B^.p^) := c;
+ Inc(B^.p);
end;
procedure luaL_putchar(B : PluaL_Buffer; c : Char);
begin
- luaL_addchar(B, c);
+ luaL_addchar(B, c);
end;
procedure luaL_addsize(B : PluaL_Buffer; n : LongInt);
@@ -999,23 +1036,24 @@
function lua_ref(L : Plua_State; lock : Boolean) : LongInt;
begin
- if lock then
- lua_ref := luaL_ref(L, LUA_REGISTRYINDEX)
- else begin
- lua_pushstring(L, 'unlocked references are obsolete');
- lua_error(L);
- lua_ref := 0;
- end;
+ if lock then
+ lua_ref := luaL_ref(L, LUA_REGISTRYINDEX)
+ else
+ begin
+ lua_pushstring(L, 'unlocked references are obsolete');
+ lua_error(L);
+ lua_ref := 0;
+ end;
end;
procedure lua_unref(L : Plua_State; ref : LongInt);
begin
- luaL_unref(L, LUA_REGISTRYINDEX, ref);
+ luaL_unref(L, LUA_REGISTRYINDEX, ref);
end;
procedure lua_getref(L : Plua_State; ref : LongInt);
begin
- lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
+ lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
end;