hedgewars/LuaPas.pas
changeset 6580 6155187bf599
parent 6453 11c578d30bd3
child 6817 daaf0834c4d2
equal deleted inserted replaced
6579:fc52f7c22c9b 6580:6155187bf599
    13 
    13 
    14 {.$DEFINE LUA_GETHOOK}
    14 {.$DEFINE LUA_GETHOOK}
    15 {$INCLUDE "config.inc"}
    15 {$INCLUDE "config.inc"}
    16 
    16 
    17 type
    17 type
    18   size_t   = Cardinal;
    18     size_t   = Cardinal;
    19   Psize_t  = ^size_t;
    19     Psize_t  = ^size_t;
    20   PPointer = ^Pointer;
    20     PPointer = ^Pointer;
    21 
    21 
    22   lua_State = record end;
    22     lua_State = record end;
    23   Plua_State = ^lua_State;
    23     Plua_State = ^lua_State;
    24 
    24 
    25 const
    25 const
    26     LuaLibName = cLuaLibrary;
    26     LuaLibName = cLuaLibrary;
    27 
    27 
    28 
    28 
    43 ** with a number type different from double. You may also need to
    43 ** with a number type different from double. You may also need to
    44 ** change lua_number2int & lua_number2integer.
    44 ** change lua_number2int & lua_number2integer.
    45 ** ===================================================================
    45 ** ===================================================================
    46 *)
    46 *)
    47 type
    47 type
    48   LUA_NUMBER_  = Double;            // ending underscore is needed in Pascal
    48     LUA_NUMBER_  = Double;            // ending underscore is needed in Pascal
    49   LUA_INTEGER_ = PtrInt;
    49     LUA_INTEGER_ = PtrInt;
    50 
    50 
    51 (*
    51 (*
    52 @@ LUA_IDSIZE gives the maximum size for the description of the source
    52 @@ LUA_IDSIZE gives the maximum size for the description of the source
    53 @* of a function in debug information.
    53 @* of a function in debug information.
    54 ** CHANGE it if you want a different size.
    54 ** CHANGE it if you want a different size.
    55 *)
    55 *)
    56 const
    56 const
    57   LUA_IDSIZE = 60;
    57     LUA_IDSIZE = 60;
    58 
    58 
    59 (*
    59 (*
    60 @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
    60 @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
    61 *)
    61 *)
    62 const
    62 const
    63   LUAL_BUFFERSIZE = 1024;
    63     LUAL_BUFFERSIZE = 1024;
    64 
    64 
    65 (*
    65 (*
    66 @@ LUA_PROMPT is the default prompt used by stand-alone Lua.
    66 @@ LUA_PROMPT is the default prompt used by stand-alone Lua.
    67 @@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua.
    67 @@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua.
    68 ** CHANGE them if you want different prompts. (You can also change the
    68 ** CHANGE them if you want different prompts. (You can also change the
    69 ** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.)
    69 ** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.)
    70 *)
    70 *)
    71 const
    71 const
    72   LUA_PROMPT  = '> ';
    72     LUA_PROMPT  = '> ';
    73   LUA_PROMPT2 = '>> ';
    73     LUA_PROMPT2 = '>> ';
    74 
    74 
    75 (*
    75 (*
    76 @@ lua_readline defines how to show a prompt and then read a line from
    76 @@ lua_readline defines how to show a prompt and then read a line from
    77 @* the standard input.
    77 @* the standard input.
    78 @@ lua_saveline defines how to "save" a read line in a "history".
    78 @@ lua_saveline defines how to "save" a read line in a "history".
    79 @@ lua_freeline defines how to free a line read by lua_readline.
    79 @@ lua_freeline defines how to free a line read by lua_readline.
    80 ** CHANGE them if you want to improve this functionality (e.g., by using
    80 ** CHANGE them if you want to improve this functionality (e.g., by using
    81 ** GNU readline and history facilities).
    81 ** GNU readline and history facilities).
    82 *)
    82 *)
    83 function  lua_readline(L : Plua_State; var b : PChar; p : PChar): Boolean;
    83 function  lua_readline(L : Plua_State;
       
    84 var b : PChar; p : PChar): Boolean;
       
    85 
    84 procedure lua_saveline(L : Plua_State; idx : LongInt);
    86 procedure lua_saveline(L : Plua_State; idx : LongInt);
       
    87 
    85 procedure lua_freeline(L : Plua_State; b : PChar);
    88 procedure lua_freeline(L : Plua_State; b : PChar);
    86 
    89 
    87 (*
    90 (*
    88 @@ lua_stdin_is_tty detects whether the standard input is a 'tty' (that
    91 @@ lua_stdin_is_tty detects whether the standard input is a 'tty' (that
    89 @* is, whether we're running lua interactively).
    92 @* is, whether we're running lua interactively).
    93 #include <io.h>
    96 #include <io.h>
    94 #include <stdio.h>
    97 #include <stdio.h>
    95 #define lua_stdin_is_tty()  _isatty(_fileno(stdin))
    98 #define lua_stdin_is_tty()  _isatty(_fileno(stdin))
    96 *)
    99 *)
    97 const
   100 const
    98   lua_stdin_is_tty = TRUE;
   101     lua_stdin_is_tty = TRUE;
    99 
   102 
   100 (*****************************************************************************)
   103 (*****************************************************************************)
   101 (*                                  lua.h                                    *)
   104 (*                                  lua.h                                    *)
   102 (*****************************************************************************)
   105 (*****************************************************************************)
   103 
   106 
   107 ** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
   110 ** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
   108 ** See Copyright Notice at the end of this file
   111 ** See Copyright Notice at the end of this file
   109 *)
   112 *)
   110 
   113 
   111 const
   114 const
   112   LUA_VERSION     = 'Lua 5.1';
   115     LUA_VERSION     = 'Lua 5.1';
   113   LUA_VERSION_NUM = 501;
   116     LUA_VERSION_NUM = 501;
   114   LUA_COPYRIGHT   = 'Copyright (C) 1994-2006 Tecgraf, PUC-Rio';
   117     LUA_COPYRIGHT   = 'Copyright (C) 1994-2006 Tecgraf, PUC-Rio';
   115   LUA_AUTHORS     = 'R. Ierusalimschy, L. H. de Figueiredo & W. Celes';
   118     LUA_AUTHORS     = 'R. Ierusalimschy, L. H. de Figueiredo & W. Celes';
   116 
   119 
   117   (* mark for precompiled code (`<esc>Lua') *)
   120     (* mark for precompiled code (`<esc>Lua') *)
   118   LUA_SIGNATURE = #27 + 'Lua';
   121     LUA_SIGNATURE = #27 + 'Lua';
   119 
   122 
   120   (* option for multiple returns in `lua_pcall' and `lua_call' *)
   123     (* option for multiple returns in `lua_pcall' and `lua_call' *)
   121   LUA_MULTRET = -1;
   124     LUA_MULTRET = -1;
   122 
   125 
   123   (*
   126     (*
   124   ** pseudo-indices
   127     ** pseudo-indices
   125   *)
   128     *)
   126   LUA_REGISTRYINDEX = -10000;
   129     LUA_REGISTRYINDEX = -10000;
   127   LUA_ENVIRONINDEX  = -10001;
   130     LUA_ENVIRONINDEX  = -10001;
   128   LUA_GLOBALSINDEX  = -10002;
   131     LUA_GLOBALSINDEX  = -10002;
   129 
   132 
   130 function lua_upvalueindex(idx : LongInt) : LongInt;   // a marco
   133 function lua_upvalueindex(idx : LongInt) : LongInt;   // a marco
   131 
   134 
   132 const
   135 const
   133   (* thread status; 0 is OK *)
   136    (* thread status; 0 is OK *)
   134   LUA_YIELD_    = 1;     // Note: the ending underscore is needed in Pascal
   137     LUA_YIELD_    = 1;     // Note: the ending underscore is needed in Pascal
   135   LUA_ERRRUN    = 2;
   138     LUA_ERRRUN    = 2;
   136   LUA_ERRSYNTAX = 3;
   139     LUA_ERRSYNTAX = 3;
   137   LUA_ERRMEM    = 4;
   140     LUA_ERRMEM    = 4;
   138   LUA_ERRERR    = 5;
   141     LUA_ERRERR    = 5;
   139 
   142 
   140 type
   143 type
   141   lua_CFunction = function(L : Plua_State) : LongInt; cdecl;
   144    lua_CFunction = function(L : Plua_State) : LongInt; cdecl;
   142 
   145 
   143   (*
   146     (*
   144   ** functions that read/write blocks when loading/dumping Lua chunks
   147     ** functions that read/write blocks when loading/dumping Lua chunks
   145   *)
   148     *)
   146   lua_Reader = function (L : Plua_State; ud : Pointer;
   149     lua_Reader = function (L : Plua_State; ud : Pointer; sz : Psize_t) : PChar; cdecl;
   147                          sz : Psize_t) : PChar; cdecl;
   150     lua_Writer = function (L : Plua_State; const p : Pointer; sz : size_t; ud : Pointer) : LongInt; cdecl;
   148   lua_Writer = function (L : Plua_State; const p : Pointer; sz : size_t;
       
   149                          ud : Pointer) : LongInt; cdecl;
       
   150 
   151 
   151   (*
   152   (*
   152   ** prototype for memory-allocation functions
   153   ** prototype for memory-allocation functions
   153   *)
   154   *)
   154   lua_Alloc = function (ud, ptr : Pointer;
   155   lua_Alloc = function (ud, ptr : Pointer; osize, nsize : size_t) : Pointer; cdecl;
   155                         osize, nsize : size_t) : Pointer; cdecl;
   156 
   156 
   157 const
   157 const
   158     (*
   158   (*
   159     ** basic types
   159   ** basic types
   160     *)
   160   *)
   161     LUA_TNONE          = -1;
   161   LUA_TNONE          = -1;
   162     LUA_TNIL           = 0;
   162 
   163     LUA_TBOOLEAN       = 1;
   163   LUA_TNIL           = 0;
   164     LUA_TLIGHTUSERDATA = 2;
   164   LUA_TBOOLEAN       = 1;
   165     LUA_TNUMBER        = 3;
   165   LUA_TLIGHTUSERDATA = 2;
   166     LUA_TSTRING        = 4;
   166   LUA_TNUMBER        = 3;
   167     LUA_TTABLE         = 5;
   167   LUA_TSTRING        = 4;
   168     LUA_TFUNCTION      = 6;
   168   LUA_TTABLE         = 5;
   169     LUA_TUSERDATA      = 7;
   169   LUA_TFUNCTION      = 6;
   170     LUA_TTHREAD        = 8;
   170   LUA_TUSERDATA      = 7;
   171 
   171   LUA_TTHREAD        = 8;
   172     (* minimum Lua stack available to a C function *)
   172 
   173     LUA_MINSTACK = 20;
   173   (* minimum Lua stack available to a C function *)
       
   174   LUA_MINSTACK = 20;
       
   175 
   174 
   176 type
   175 type
   177   (* type of numbers in Lua *)
   176     (* type of numbers in Lua *)
   178   lua_Number = LUA_NUMBER_;
   177     lua_Number = LUA_NUMBER_;
   179 
   178 
   180   (* type for integer functions *)
   179     (* type for integer functions *)
   181   lua_Integer = LUA_INTEGER_;
   180     lua_Integer = LUA_INTEGER_;
   182 
   181 
   183 (*
   182 (*
   184 ** state manipulation
   183 ** state manipulation
   185 *)
   184 *)
   186 function  lua_newstate(f : lua_Alloc; ud : Pointer) : Plua_State;
   185 function  lua_newstate(f : lua_Alloc; ud : Pointer) : Plua_State;
   187   cdecl; external LuaLibName;
   186     cdecl; external LuaLibName;
       
   187     
   188 procedure lua_close(L: Plua_State);
   188 procedure lua_close(L: Plua_State);
   189   cdecl; external LuaLibName;
   189     cdecl; external LuaLibName;
   190 function  lua_newthread(L : Plua_State) : Plua_State;
   190 function  lua_newthread(L : Plua_State) : Plua_State;
   191   cdecl; external LuaLibName;
   191     cdecl; external LuaLibName;
   192 
   192 
   193 function  lua_atpanic(L : Plua_State; panicf : lua_CFunction) : lua_CFunction;
   193 function  lua_atpanic(L : Plua_State; panicf : lua_CFunction) : lua_CFunction;
   194   cdecl; external LuaLibName;
   194     cdecl; external LuaLibName;
   195 
   195 
   196 
   196 
   197 (*
   197 (*
   198 ** basic stack manipulation
   198 ** basic stack manipulation
   199 *)
   199 *)
   200 function  lua_gettop(L : Plua_State) : LongInt;
   200 function  lua_gettop(L : Plua_State) : LongInt;
   201   cdecl; external LuaLibName;
   201     cdecl; external LuaLibName;
       
   202     
   202 procedure lua_settop(L : Plua_State; idx : LongInt);
   203 procedure lua_settop(L : Plua_State; idx : LongInt);
   203   cdecl; external LuaLibName;
   204     cdecl; external LuaLibName;
       
   205     
   204 procedure lua_pushvalue(L : Plua_State; idx : LongInt);
   206 procedure lua_pushvalue(L : Plua_State; idx : LongInt);
   205   cdecl; external LuaLibName;
   207     cdecl; external LuaLibName;
       
   208     
   206 procedure lua_remove(L : Plua_State; idx : LongInt);
   209 procedure lua_remove(L : Plua_State; idx : LongInt);
   207   cdecl; external LuaLibName;
   210     cdecl; external LuaLibName;
       
   211     
   208 procedure lua_insert(L : Plua_State; idx : LongInt);
   212 procedure lua_insert(L : Plua_State; idx : LongInt);
   209   cdecl; external LuaLibName;
   213     cdecl; external LuaLibName;
       
   214     
   210 procedure lua_replace(L : Plua_State; idx : LongInt);
   215 procedure lua_replace(L : Plua_State; idx : LongInt);
   211   cdecl; external LuaLibName;
   216     cdecl; external LuaLibName;
       
   217     
   212 function  lua_checkstack(L : Plua_State; sz : LongInt) : LongBool;
   218 function  lua_checkstack(L : Plua_State; sz : LongInt) : LongBool;
   213   cdecl; external LuaLibName;
   219     cdecl; external LuaLibName;
   214 
   220 
   215 procedure lua_xmove(src, dest : Plua_State; n : LongInt);
   221 procedure lua_xmove(src, dest : Plua_State; n : LongInt);
   216   cdecl; external LuaLibName;
   222     cdecl; external LuaLibName;
   217 
   223 
   218 
   224 
   219 (*
   225 (*
   220 ** access functions (stack -> C)
   226 ** access functions (stack -> C)
   221 *)
   227 *)
   222 function lua_isnumber(L : Plua_State; idx : LongInt) : LongBool;
   228 function lua_isnumber(L : Plua_State; idx : LongInt) : LongBool;
   223   cdecl; external LuaLibName;
   229     cdecl; external LuaLibName;
       
   230     
   224 function lua_isstring(L : Plua_State; idx : LongInt) : LongBool;
   231 function lua_isstring(L : Plua_State; idx : LongInt) : LongBool;
   225   cdecl; external LuaLibName;
   232     cdecl; external LuaLibName;
       
   233     
   226 function lua_iscfunction(L : Plua_State; idx : LongInt) : LongBool;
   234 function lua_iscfunction(L : Plua_State; idx : LongInt) : LongBool;
   227   cdecl; external LuaLibName;
   235     cdecl; external LuaLibName;
       
   236     
   228 function lua_isuserdata(L : Plua_State; idx : LongInt) : LongBool;
   237 function lua_isuserdata(L : Plua_State; idx : LongInt) : LongBool;
   229   cdecl; external LuaLibName;
   238     cdecl; external LuaLibName;
       
   239     
   230 function lua_type(L : Plua_State; idx : LongInt) : LongInt;
   240 function lua_type(L : Plua_State; idx : LongInt) : LongInt;
   231   cdecl; external LuaLibName;
   241     cdecl; external LuaLibName;
       
   242     
   232 function lua_typename(L : Plua_State; tp : LongInt) : PChar;
   243 function lua_typename(L : Plua_State; tp : LongInt) : PChar;
   233   cdecl; external LuaLibName;
   244     cdecl; external LuaLibName;
   234 
   245 
       
   246     
   235 function lua_equal(L : Plua_State; idx1, idx2 : LongInt) : LongBool;
   247 function lua_equal(L : Plua_State; idx1, idx2 : LongInt) : LongBool;
   236   cdecl; external LuaLibName;
   248     cdecl; external LuaLibName;
       
   249     
   237 function lua_rawequal(L : Plua_State; idx1, idx2 : LongInt) : LongBool;
   250 function lua_rawequal(L : Plua_State; idx1, idx2 : LongInt) : LongBool;
   238   cdecl; external LuaLibName;
   251     cdecl; external LuaLibName;
       
   252     
   239 function lua_lessthan(L : Plua_State; idx1, idx2 : LongInt) : LongBool;
   253 function lua_lessthan(L : Plua_State; idx1, idx2 : LongInt) : LongBool;
   240   cdecl; external LuaLibName;
   254     cdecl; external LuaLibName;
   241 
   255 
   242 function lua_tonumber(L : Plua_State; idx : LongInt) : lua_Number;
   256 function lua_tonumber(L : Plua_State; idx : LongInt) : lua_Number;
   243   cdecl; external LuaLibName;
   257     cdecl; external LuaLibName;
       
   258     
   244 function lua_tointeger(L : Plua_State; idx : LongInt) : lua_Integer;
   259 function lua_tointeger(L : Plua_State; idx : LongInt) : lua_Integer;
   245   cdecl; external LuaLibName;
   260     cdecl; external LuaLibName;
       
   261     
   246 function lua_toboolean(L : Plua_State; idx : LongInt) : LongBool;
   262 function lua_toboolean(L : Plua_State; idx : LongInt) : LongBool;
   247   cdecl; external LuaLibName;
   263     cdecl; external LuaLibName;
   248 function lua_tolstring(L : Plua_State; idx : LongInt;
   264     
   249                        len : Psize_t) : PChar;
   265     
   250   cdecl; external LuaLibName;
   266 function lua_tolstring(L : Plua_State; idx : LongInt; len : Psize_t) : PChar;
       
   267     cdecl; external LuaLibName;
       
   268     
   251 function lua_objlen(L : Plua_State; idx : LongInt) : size_t;
   269 function lua_objlen(L : Plua_State; idx : LongInt) : size_t;
   252   cdecl; external LuaLibName;
   270     cdecl; external LuaLibName;
       
   271     
   253 function lua_tocfunction(L : Plua_State; idx : LongInt) : lua_CFunction;
   272 function lua_tocfunction(L : Plua_State; idx : LongInt) : lua_CFunction;
   254   cdecl; external LuaLibName;
   273     cdecl; external LuaLibName;
       
   274     
   255 function lua_touserdata(L : Plua_State; idx : LongInt) : Pointer;
   275 function lua_touserdata(L : Plua_State; idx : LongInt) : Pointer;
   256   cdecl; external LuaLibName;
   276     cdecl; external LuaLibName;
       
   277     
   257 function lua_tothread(L : Plua_State; idx : LongInt) : Plua_State;
   278 function lua_tothread(L : Plua_State; idx : LongInt) : Plua_State;
   258   cdecl; external LuaLibName;
   279     cdecl; external LuaLibName;
       
   280     
   259 function lua_topointer(L : Plua_State; idx : LongInt) : Pointer;
   281 function lua_topointer(L : Plua_State; idx : LongInt) : Pointer;
   260   cdecl; external LuaLibName;
   282     cdecl; external LuaLibName;
   261 
   283 
   262 
   284 
   263 (*
   285 (*
   264 ** push functions (C -> stack)
   286 ** push functions (C -> stack)
   265 *)
   287 *)
   266 procedure lua_pushnil(L : Plua_State);
   288 procedure lua_pushnil(L : Plua_State);
   267   cdecl; external LuaLibName;
   289     cdecl; external LuaLibName;
       
   290     
   268 procedure lua_pushnumber(L : Plua_State; n : lua_Number);
   291 procedure lua_pushnumber(L : Plua_State; n : lua_Number);
   269   cdecl; external LuaLibName;
   292     cdecl; external LuaLibName;
       
   293     
   270 procedure lua_pushinteger(L : Plua_State; n : lua_Integer);
   294 procedure lua_pushinteger(L : Plua_State; n : lua_Integer);
   271   cdecl; external LuaLibName;
   295     cdecl; external LuaLibName;
       
   296     
   272 procedure lua_pushlstring(L : Plua_State; const s : PChar; ls : size_t);
   297 procedure lua_pushlstring(L : Plua_State; const s : PChar; ls : size_t);
   273   cdecl; external LuaLibName;
   298     cdecl; external LuaLibName;
       
   299     
   274 procedure lua_pushstring(L : Plua_State; const s : PChar);
   300 procedure lua_pushstring(L : Plua_State; const s : PChar);
   275   cdecl; external LuaLibName;
   301     cdecl; external LuaLibName;
       
   302     
       
   303     
   276 function  lua_pushvfstring(L : Plua_State;
   304 function  lua_pushvfstring(L : Plua_State;
   277                            const fmt : PChar; argp : Pointer) : PChar;
   305     const fmt : PChar; argp : Pointer) : PChar;
   278   cdecl; external LuaLibName;
   306     cdecl; external LuaLibName;
       
   307     
   279 function  lua_pushfstring(L : Plua_State; const fmt : PChar) : PChar; varargs;
   308 function  lua_pushfstring(L : Plua_State; const fmt : PChar) : PChar; varargs;
   280   cdecl; external LuaLibName;
   309     cdecl; external LuaLibName;
       
   310     
   281 procedure lua_pushcclosure(L : Plua_State; fn : lua_CFunction; n : LongInt);
   311 procedure lua_pushcclosure(L : Plua_State; fn : lua_CFunction; n : LongInt);
   282   cdecl; external LuaLibName;
   312     cdecl; external LuaLibName;
       
   313     
   283 procedure lua_pushboolean(L : Plua_State; b : LongBool);
   314 procedure lua_pushboolean(L : Plua_State; b : LongBool);
   284   cdecl; external LuaLibName;
   315     cdecl; external LuaLibName;
       
   316     
   285 procedure lua_pushlightuserdata(L : Plua_State; p : Pointer);
   317 procedure lua_pushlightuserdata(L : Plua_State; p : Pointer);
   286   cdecl; external LuaLibName;
   318     cdecl; external LuaLibName;
       
   319     
   287 function  lua_pushthread(L : Plua_state) : Cardinal;
   320 function  lua_pushthread(L : Plua_state) : Cardinal;
   288   cdecl; external LuaLibName;
   321     cdecl; external LuaLibName;
   289 
   322 
   290 
   323 
   291 (*
   324 (*
   292 ** get functions (Lua -> stack)
   325 ** get functions (Lua -> stack)
   293 *)
   326 *)
   294 procedure lua_gettable(L : Plua_State ; idx : LongInt);
   327 procedure lua_gettable(L : Plua_State ; idx : LongInt);
   295   cdecl; external LuaLibName;
   328     cdecl; external LuaLibName;
       
   329     
   296 procedure lua_getfield(L : Plua_State; idx : LongInt; k : PChar);
   330 procedure lua_getfield(L : Plua_State; idx : LongInt; k : PChar);
   297   cdecl; external LuaLibName;
   331     cdecl; external LuaLibName;
       
   332     
   298 procedure lua_rawget(L : Plua_State; idx : LongInt);
   333 procedure lua_rawget(L : Plua_State; idx : LongInt);
   299   cdecl; external LuaLibName;
   334     cdecl; external LuaLibName;
       
   335     
   300 procedure lua_rawgeti(L : Plua_State; idx, n : LongInt);
   336 procedure lua_rawgeti(L : Plua_State; idx, n : LongInt);
   301   cdecl; external LuaLibName;
   337     cdecl; external LuaLibName;
       
   338     
   302 procedure lua_createtable(L : Plua_State; narr, nrec : LongInt);
   339 procedure lua_createtable(L : Plua_State; narr, nrec : LongInt);
   303   cdecl; external LuaLibName;
   340     cdecl; external LuaLibName;
       
   341     
   304 function  lua_newuserdata(L : Plua_State; sz : size_t) : Pointer;
   342 function  lua_newuserdata(L : Plua_State; sz : size_t) : Pointer;
   305   cdecl; external LuaLibName;
   343     cdecl; external LuaLibName;
       
   344     
   306 function  lua_getmetatable(L : Plua_State; objindex : LongInt) : LongBool;
   345 function  lua_getmetatable(L : Plua_State; objindex : LongInt) : LongBool;
   307   cdecl; external LuaLibName;
   346     cdecl; external LuaLibName;
       
   347     
   308 procedure lua_getfenv(L : Plua_State; idx : LongInt);
   348 procedure lua_getfenv(L : Plua_State; idx : LongInt);
   309   cdecl; external LuaLibName;
   349     cdecl; external LuaLibName;
   310 
   350 
   311 
   351 
   312 (*
   352 (*
   313 ** set functions (stack -> Lua)
   353 ** set functions (stack -> Lua)
   314 *)
   354 *)
   315 procedure lua_settable(L : Plua_State; idx : LongInt);
   355 procedure lua_settable(L : Plua_State; idx : LongInt);
   316   cdecl; external LuaLibName;
   356     cdecl; external LuaLibName;
       
   357     
   317 procedure lua_setfield(L : Plua_State; idx : LongInt; const k : PChar);
   358 procedure lua_setfield(L : Plua_State; idx : LongInt; const k : PChar);
   318   cdecl; external LuaLibName;
   359     cdecl; external LuaLibName;
       
   360     
   319 procedure lua_rawset(L : Plua_State; idx : LongInt);
   361 procedure lua_rawset(L : Plua_State; idx : LongInt);
   320   cdecl; external LuaLibName;
   362     cdecl; external LuaLibName;
       
   363     
   321 procedure lua_rawseti(L : Plua_State; idx , n: LongInt);
   364 procedure lua_rawseti(L : Plua_State; idx , n: LongInt);
   322   cdecl; external LuaLibName;
   365     cdecl; external LuaLibName;
       
   366     
   323 function lua_setmetatable(L : Plua_State; objindex : LongInt): LongBool;
   367 function lua_setmetatable(L : Plua_State; objindex : LongInt): LongBool;
   324   cdecl; external LuaLibName;
   368     cdecl; external LuaLibName;
       
   369     
   325 function lua_setfenv(L : Plua_State; idx : LongInt): LongBool;
   370 function lua_setfenv(L : Plua_State; idx : LongInt): LongBool;
   326   cdecl; external LuaLibName;
   371     cdecl; external LuaLibName;
   327 
   372 
   328 (*
   373 (*
   329 ** `load' and `call' functions (load and run Lua code)
   374 ** `load' and `call' functions (load and run Lua code)
   330 *)
   375 *)
   331 procedure lua_call(L : Plua_State; nargs, nresults : LongInt);
   376 procedure lua_call(L : Plua_State; nargs, nresults : LongInt);
   332   cdecl; external LuaLibName;
   377     cdecl; external LuaLibName;
   333 function  lua_pcall(L : Plua_State;
   378     
   334                     nargs, nresults, errfunc : LongInt) : LongInt;
   379 function  lua_pcall(L : Plua_State; nargs, nresults, errfunc : LongInt) : LongInt;
   335   cdecl; external LuaLibName;
   380     cdecl; external LuaLibName;
   336 function  lua_cpcall(L : Plua_State;
   381     
   337                      func : lua_CFunction; ud : Pointer) : LongInt;
   382 function  lua_cpcall(L : Plua_State; func : lua_CFunction; ud : Pointer) : LongInt;
   338   cdecl; external LuaLibName;
   383     cdecl; external LuaLibName;
   339 function  lua_load(L : Plua_State; reader : lua_Reader;
   384     
   340                    dt : Pointer; const chunkname : PChar) : LongInt;
   385 function  lua_load(L : Plua_State; reader : lua_Reader; dt : Pointer; const chunkname : PChar) : LongInt;
   341   cdecl; external LuaLibName;
   386     cdecl; external LuaLibName;
       
   387     
   342 
   388 
   343 function lua_dump(L : Plua_State; writer : lua_Writer; data: Pointer) : LongInt;
   389 function lua_dump(L : Plua_State; writer : lua_Writer; data: Pointer) : LongInt;
   344   cdecl; external LuaLibName;
   390     cdecl; external LuaLibName;
   345 
   391 
   346 
   392 
   347 (*
   393 (*
   348 ** coroutine functions
   394 ** coroutine functions
   349 *)
   395 *)
   350 function lua_yield(L : Plua_State; nresults : LongInt) : LongInt;
   396 function lua_yield(L : Plua_State; nresults : LongInt) : LongInt;
   351   cdecl; external LuaLibName;
   397     cdecl; external LuaLibName;
       
   398     
   352 function lua_resume(L : Plua_State; narg : LongInt) : LongInt;
   399 function lua_resume(L : Plua_State; narg : LongInt) : LongInt;
   353   cdecl; external LuaLibName;
   400     cdecl; external LuaLibName;
       
   401     
   354 function lua_status(L : Plua_State) : LongInt;
   402 function lua_status(L : Plua_State) : LongInt;
   355   cdecl; external LuaLibName;
   403     cdecl; external LuaLibName;
   356 
   404 
   357 (*
   405 (*
   358 ** garbage-collection functions and options
   406 ** garbage-collection functions and options
   359 *)
   407 *)
   360 const
   408 const
   361   LUA_GCSTOP       = 0;
   409     LUA_GCSTOP       = 0;
   362   LUA_GCRESTART    = 1;
   410     LUA_GCRESTART    = 1;
   363   LUA_GCCOLLECT    = 2;
   411     LUA_GCCOLLECT    = 2;
   364   LUA_GCCOUNT      = 3;
   412     LUA_GCCOUNT      = 3;
   365   LUA_GCCOUNTB     = 4;
   413     LUA_GCCOUNTB     = 4;
   366   LUA_GCSTEP       = 5;
   414     LUA_GCSTEP       = 5;
   367   LUA_GCSETPAUSE   = 6;
   415     LUA_GCSETPAUSE   = 6;
   368   LUA_GCSETSTEPMUL = 7;
   416     LUA_GCSETSTEPMUL = 7;
   369 
   417 
   370 function lua_gc(L : Plua_State; what, data : LongInt) : LongInt;
   418 function lua_gc(L : Plua_State; what, data : LongInt) : LongInt;
   371   cdecl; external LuaLibName;
   419     cdecl; external LuaLibName;
   372 
   420 
   373 (*
   421 (*
   374 ** miscellaneous functions
   422 ** miscellaneous functions
   375 *)
   423 *)
   376 function lua_error(L : Plua_State) : LongInt;
   424 function lua_error(L : Plua_State) : LongInt;
   377   cdecl; external LuaLibName;
   425     cdecl; external LuaLibName;
   378 
   426 
   379 function lua_next(L : Plua_State; idx : LongInt) : LongInt;
   427 function lua_next(L : Plua_State; idx : LongInt) : LongInt;
   380   cdecl; external LuaLibName;
   428     cdecl; external LuaLibName;
   381 
   429 
   382 procedure lua_concat(L : Plua_State; n : LongInt);
   430 procedure lua_concat(L : Plua_State; n : LongInt);
   383   cdecl; external LuaLibName;
   431     cdecl; external LuaLibName;
   384 
   432 
   385 function  lua_getallocf(L : Plua_State; ud : PPointer) : lua_Alloc;
   433 function  lua_getallocf(L : Plua_State; ud : PPointer) : lua_Alloc;
   386   cdecl; external LuaLibName;
   434     cdecl; external LuaLibName;
       
   435     
   387 procedure lua_setallocf(L : Plua_State; f : lua_Alloc; ud : Pointer);
   436 procedure lua_setallocf(L : Plua_State; f : lua_Alloc; ud : Pointer);
   388   cdecl; external LuaLibName;
   437     cdecl; external LuaLibName;
   389 
   438 
   390 (*
   439 (*
   391 ** ===============================================================
   440 ** ===============================================================
   392 ** some useful macros
   441 ** some useful macros
   393 ** ===============================================================
   442 ** ===============================================================
   427 procedure lua_getregistry(L : Plua_State);
   476 procedure lua_getregistry(L : Plua_State);
   428 
   477 
   429 function lua_getgccount(L : Plua_State) : LongInt;
   478 function lua_getgccount(L : Plua_State) : LongInt;
   430 
   479 
   431 type
   480 type
   432   lua_Chuckreader = lua_Reader;
   481     lua_Chuckreader = lua_Reader;
   433   lua_Chuckwriter = lua_Writer;
   482     lua_Chuckwriter = lua_Writer;
   434 
   483 
   435 (* ====================================================================== *)
   484 (* ====================================================================== *)
   436 
   485 
   437 (*
   486 (*
   438 ** {======================================================================
   487 ** {======================================================================
   442 
   491 
   443 (*
   492 (*
   444 ** Event codes
   493 ** Event codes
   445 *)
   494 *)
   446 const
   495 const
   447   LUA_HOOKCALL    = 0;
   496     LUA_HOOKCALL    = 0;
   448   LUA_HOOKRET     = 1;
   497     LUA_HOOKRET     = 1;
   449   LUA_HOOKLINE    = 2;
   498     LUA_HOOKLINE    = 2;
   450   LUA_HOOKCOUNT   = 3;
   499     LUA_HOOKCOUNT   = 3;
   451   LUA_HOOKTAILRET = 4;
   500     LUA_HOOKTAILRET = 4;
   452 
   501 
   453 
   502 
   454 (*
   503 (*
   455 ** Event masks
   504 ** Event masks
   456 *)
   505 *)
   457   LUA_MASKCALL  = 1 shl LUA_HOOKCALL;
   506     LUA_MASKCALL  = 1 shl LUA_HOOKCALL;
   458   LUA_MASKRET   = 1 shl LUA_HOOKRET;
   507     LUA_MASKRET   = 1 shl LUA_HOOKRET;
   459   LUA_MASKLINE  = 1 shl LUA_HOOKLINE;
   508     LUA_MASKLINE  = 1 shl LUA_HOOKLINE;
   460   LUA_MASKCOUNT = 1 shl LUA_HOOKCOUNT;
   509     LUA_MASKCOUNT = 1 shl LUA_HOOKCOUNT;
   461 
   510 
   462 type
   511 type
   463   lua_Debug = packed record
   512     lua_Debug = packed record
   464     event : LongInt;
   513     event : LongInt;
   465     name : PChar;          (* (n) *)
   514     name : PChar;          (* (n) *)
   466     namewhat : PChar;      (* (n) `global', `local', `field', `method' *)
   515     namewhat : PChar;      (* (n) `global', `local', `field', `method' *)
   467     what : PChar;          (* (S) `Lua', `C', `main', `tail' *)
   516     what : PChar;          (* (S) `Lua', `C', `main', `tail' *)
   468     source : PChar;        (* (S) *)
   517     source : PChar;        (* (S) *)
   470     nups : LongInt;        (* (u) number of upvalues *)
   519     nups : LongInt;        (* (u) number of upvalues *)
   471     linedefined : LongInt; (* (S) *)
   520     linedefined : LongInt; (* (S) *)
   472     short_src : array [0..LUA_IDSIZE-1] of Char; (* (S) *)
   521     short_src : array [0..LUA_IDSIZE-1] of Char; (* (S) *)
   473     (* private part *)
   522     (* private part *)
   474     i_ci : LongInt;        (* active function *)
   523     i_ci : LongInt;        (* active function *)
   475   end;
   524     end;
   476   Plua_Debug = ^lua_Debug;
   525     Plua_Debug = ^lua_Debug;
   477 
   526 
   478   (* Functions to be called by the debuger in specific events *)
   527   (* Functions to be called by the debuger in specific events *)
   479   lua_Hook = procedure (L : Plua_State; ar : Plua_Debug); cdecl;
   528   lua_Hook = procedure (L : Plua_State; ar : Plua_Debug); cdecl;
   480 
   529 
   481 
   530 
   482 function lua_getstack(L : Plua_State; level : LongInt;
   531 function lua_getstack(L : Plua_State; level : LongInt; ar : Plua_Debug) : LongInt;
   483                       ar : Plua_Debug) : LongInt;
   532     cdecl; external LuaLibName;
   484   cdecl; external LuaLibName;
   533     
   485 function lua_getinfo(L : Plua_State; const what : PChar;
   534 function lua_getinfo(L : Plua_State; const what : PChar; ar: Plua_Debug): LongInt;
   486                      ar: Plua_Debug): LongInt;
   535     cdecl; external LuaLibName;
   487   cdecl; external LuaLibName;
   536     
   488 function lua_getlocal(L : Plua_State;
   537 function lua_getlocal(L : Plua_State; ar : Plua_Debug; n : LongInt) : PChar;
   489                       ar : Plua_Debug; n : LongInt) : PChar;
   538     cdecl; external LuaLibName;
   490   cdecl; external LuaLibName;
   539     
   491 function lua_setlocal(L : Plua_State;
   540 function lua_setlocal(L : Plua_State; ar : Plua_Debug; n : LongInt) : PChar;
   492                       ar : Plua_Debug; n : LongInt) : PChar;
   541     cdecl; external LuaLibName;
   493   cdecl; external LuaLibName;
   542     
   494 function lua_getupvalue(L : Plua_State; funcindex, n : LongInt) : PChar;
   543 function lua_getupvalue(L : Plua_State; funcindex, n : LongInt) : PChar;
   495   cdecl; external LuaLibName;
   544     cdecl; external LuaLibName;
       
   545     
   496 function lua_setupvalue(L : Plua_State; funcindex, n : LongInt) : PChar;
   546 function lua_setupvalue(L : Plua_State; funcindex, n : LongInt) : PChar;
   497   cdecl; external LuaLibName;
   547     cdecl; external LuaLibName;
   498 
   548 
   499 function lua_sethook(L : Plua_State; func : lua_Hook;
   549 function lua_sethook(L : Plua_State; func : lua_Hook; mask, count: LongInt): LongInt;
   500                      mask, count: LongInt): LongInt;
   550     cdecl; external LuaLibName;
   501   cdecl; external LuaLibName;
   551   
   502 {$IFDEF LUA_GETHOOK}
   552 {$IFDEF LUA_GETHOOK}
   503 function lua_gethook(L : Plua_State) : lua_Hook;
   553 function lua_gethook(L : Plua_State) : lua_Hook;
   504   cdecl; external LuaLibName;
   554     cdecl; external LuaLibName;
   505 {$ENDIF}
   555 {$ENDIF}
   506 
   556 
   507 function lua_gethookmask(L : Plua_State) : LongInt;
   557 function lua_gethookmask(L : Plua_State) : LongInt;
   508   cdecl; external LuaLibName;
   558     cdecl; external LuaLibName;
       
   559     
   509 function lua_gethookcount(L : Plua_State) : LongInt;
   560 function lua_gethookcount(L : Plua_State) : LongInt;
   510   cdecl; external LuaLibName;
   561     cdecl; external LuaLibName;
   511 
   562 
   512 
   563 
   513 (*****************************************************************************)
   564 (*****************************************************************************)
   514 (*                                  lualib.h                                 *)
   565 (*                                  lualib.h                                 *)
   515 (*****************************************************************************)
   566 (*****************************************************************************)
   519 ** Lua standard libraries
   570 ** Lua standard libraries
   520 ** See Copyright Notice at the end of this file
   571 ** See Copyright Notice at the end of this file
   521 *)
   572 *)
   522 
   573 
   523 const
   574 const
   524   (* Key to file-handle type *)
   575     (* Key to file-handle type *)
   525   LUA_FILEHANDLE  = 'FILE*';
   576     LUA_FILEHANDLE  = 'FILE*';
   526 
   577 
   527   LUA_COLIBNAME   = 'coroutine';
   578     LUA_COLIBNAME   = 'coroutine';
   528   LUA_TABLIBNAME  = 'table';
   579     LUA_TABLIBNAME  = 'table';
   529   LUA_IOLIBNAME   = 'io';
   580     LUA_IOLIBNAME   = 'io';
   530   LUA_OSLIBNAME   = 'os';
   581     LUA_OSLIBNAME   = 'os';
   531   LUA_STRLIBNAME  = 'string';
   582     LUA_STRLIBNAME  = 'string';
   532   LUA_MATHLIBNAME = 'math';
   583     LUA_MATHLIBNAME = 'math';
   533   LUA_DBLIBNAME   = 'debug';
   584     LUA_DBLIBNAME   = 'debug';
   534   LUA_LOADLIBNAME = 'package';
   585     LUA_LOADLIBNAME = 'package';
   535 
   586 
   536 function luaopen_base(L : Plua_State) : LongInt;
   587 function luaopen_base(L : Plua_State) : LongInt;
   537   cdecl; external LuaLibName;
   588     cdecl; external LuaLibName;
   538 
   589 
   539 function luaopen_table(L : Plua_State) : LongInt;
   590 function luaopen_table(L : Plua_State) : LongInt;
   540   cdecl; external LuaLibName;
   591     cdecl; external LuaLibName;
   541 
   592 
   542 function luaopen_io(L : Plua_State) : LongInt;
   593 function luaopen_io(L : Plua_State) : LongInt;
   543   cdecl; external LuaLibName;
   594     cdecl; external LuaLibName;
   544 
   595 
   545 function luaopen_os(L : Plua_State) : LongInt;
   596 function luaopen_os(L : Plua_State) : LongInt;
   546   cdecl; external LuaLibName;
   597     cdecl; external LuaLibName;
   547 
   598 
   548 function luaopen_string(L : Plua_State) : LongInt;
   599 function luaopen_string(L : Plua_State) : LongInt;
   549   cdecl; external LuaLibName;
   600     cdecl; external LuaLibName;
   550 
   601 
   551 function luaopen_math(L : Plua_State) : LongInt;
   602 function luaopen_math(L : Plua_State) : LongInt;
   552   cdecl; external LuaLibName;
   603     cdecl; external LuaLibName;
   553 
   604 
   554 function luaopen_debug(L : Plua_State) : LongInt;
   605 function luaopen_debug(L : Plua_State) : LongInt;
   555   cdecl; external LuaLibName;
   606     cdecl; external LuaLibName;
   556 
   607 
   557 function luaopen_package(L : Plua_State) : LongInt;
   608 function luaopen_package(L : Plua_State) : LongInt;
   558   cdecl; external LuaLibName;
   609     cdecl; external LuaLibName;
   559 
   610 
   560 procedure luaL_openlibs(L : Plua_State);
   611 procedure luaL_openlibs(L : Plua_State);
   561   cdecl; external LuaLibName;
   612     cdecl; external LuaLibName;
   562 
   613 
   563 procedure lua_assert(x : Boolean);    // a macro
   614 procedure lua_assert(x : Boolean);    // a macro
   564 
   615 
   565 
   616 
   566 (*****************************************************************************)
   617 (*****************************************************************************)
   576 // not compatibility with the behavior of setn/getn in Lua 5.0
   627 // not compatibility with the behavior of setn/getn in Lua 5.0
   577 function  luaL_getn(L : Plua_State; idx : LongInt) : LongInt;
   628 function  luaL_getn(L : Plua_State; idx : LongInt) : LongInt;
   578 procedure luaL_setn(L : Plua_State; i, j : LongInt);
   629 procedure luaL_setn(L : Plua_State; i, j : LongInt);
   579 
   630 
   580 const
   631 const
   581   LUA_ERRFILE = LUA_ERRERR + 1;
   632     LUA_ERRFILE = LUA_ERRERR + 1;
   582 
   633 
   583 type
   634 type
   584   luaL_Reg = packed record
   635     luaL_Reg = packed record
   585     name : PChar;
   636     name : PChar;
   586     func : lua_CFunction;
   637     func : lua_CFunction;
   587   end;
   638     end;
   588   PluaL_Reg = ^luaL_Reg;
   639     PluaL_Reg = ^luaL_Reg;
   589 
   640 
   590 
   641 
   591 procedure luaL_openlib(L : Plua_State; const libname : PChar;
   642 procedure luaL_openlib(L : Plua_State; const libname : PChar; const lr : PluaL_Reg; nup : LongInt);
   592                        const lr : PluaL_Reg; nup : LongInt);
   643     cdecl; external LuaLibName;
   593   cdecl; external LuaLibName;
   644 procedure luaL_register(L : Plua_State; const libname : PChar; const lr : PluaL_Reg);
   594 procedure luaL_register(L : Plua_State; const libname : PChar;
   645     cdecl; external LuaLibName;
   595                        const lr : PluaL_Reg);
   646 function luaL_getmetafield(L : Plua_State; obj : LongInt; const e : PChar) : LongInt;
   596   cdecl; external LuaLibName;
   647     cdecl; external LuaLibName;
   597 function luaL_getmetafield(L : Plua_State; obj : LongInt;
   648 function luaL_callmeta(L : Plua_State; obj : LongInt; const e : PChar) : LongInt;
   598                            const e : PChar) : LongInt;
   649     cdecl; external LuaLibName;
   599   cdecl; external LuaLibName;
   650 function luaL_typerror(L : Plua_State; narg : LongInt; const tname : PChar) : LongInt;
   600 function luaL_callmeta(L : Plua_State; obj : LongInt;
   651     cdecl; external LuaLibName;
   601                        const e : PChar) : LongInt;
   652 function luaL_argerror(L : Plua_State; numarg : LongInt; const extramsg : PChar) : LongInt;
   602   cdecl; external LuaLibName;
   653     cdecl; external LuaLibName;
   603 function luaL_typerror(L : Plua_State; narg : LongInt;
   654 function luaL_checklstring(L : Plua_State; numArg : LongInt; ls : Psize_t) : PChar;
   604                        const tname : PChar) : LongInt;
   655     cdecl; external LuaLibName;
   605   cdecl; external LuaLibName;
   656 function luaL_optlstring(L : Plua_State; numArg : LongInt; const def: PChar; ls: Psize_t) : PChar;
   606 function luaL_argerror(L : Plua_State; numarg : LongInt;
   657     cdecl; external LuaLibName;
   607                        const extramsg : PChar) : LongInt;
       
   608   cdecl; external LuaLibName;
       
   609 function luaL_checklstring(L : Plua_State; numArg : LongInt;
       
   610                            ls : Psize_t) : PChar;
       
   611   cdecl; external LuaLibName;
       
   612 function luaL_optlstring(L : Plua_State; numArg : LongInt;
       
   613                          const def: PChar; ls: Psize_t) : PChar;
       
   614   cdecl; external LuaLibName;
       
   615 function luaL_checknumber(L : Plua_State; numArg : LongInt) : lua_Number;
   658 function luaL_checknumber(L : Plua_State; numArg : LongInt) : lua_Number;
   616   cdecl; external LuaLibName;
   659     cdecl; external LuaLibName;
   617 function luaL_optnumber(L : Plua_State; nArg : LongInt;
   660 function luaL_optnumber(L : Plua_State; nArg : LongInt; def : lua_Number) : lua_Number;
   618                         def : lua_Number) : lua_Number;
   661     cdecl; external LuaLibName;
   619   cdecl; external LuaLibName;
       
   620 
   662 
   621 function luaL_checkinteger(L : Plua_State; numArg : LongInt) : lua_Integer;
   663 function luaL_checkinteger(L : Plua_State; numArg : LongInt) : lua_Integer;
   622   cdecl; external LuaLibName;
   664     cdecl; external LuaLibName;
   623 function luaL_optinteger(L : Plua_State; nArg : LongInt;
   665 function luaL_optinteger(L : Plua_State; nArg : LongInt; def : lua_Integer) : lua_Integer;
   624                         def : lua_Integer) : lua_Integer;
   666     cdecl; external LuaLibName;
   625   cdecl; external LuaLibName;
       
   626 
   667 
   627 procedure luaL_checkstack(L : Plua_State; sz : LongInt; const msg : PChar);
   668 procedure luaL_checkstack(L : Plua_State; sz : LongInt; const msg : PChar);
   628   cdecl; external LuaLibName;
   669     cdecl; external LuaLibName;
   629 procedure luaL_checktype(L : Plua_State; narg, t : LongInt);
   670 procedure luaL_checktype(L : Plua_State; narg, t : LongInt);
   630   cdecl; external LuaLibName;
   671     cdecl; external LuaLibName;
   631 procedure luaL_checkany(L : Plua_State; narg : LongInt);
   672 procedure luaL_checkany(L : Plua_State; narg : LongInt);
   632   cdecl; external LuaLibName;
   673     cdecl; external LuaLibName;
   633 
   674 
   634 function luaL_newmetatable(L : Plua_State; const tname : PChar) : LongInt;
   675 function luaL_newmetatable(L : Plua_State; const tname : PChar) : LongInt;
   635   cdecl; external LuaLibName;
   676     cdecl; external LuaLibName;
   636 function luaL_checkudata(L : Plua_State; ud : LongInt;
   677 function luaL_checkudata(L : Plua_State; ud : LongInt; const tname : PChar) : Pointer;
   637                          const tname : PChar) : Pointer;
   678     cdecl; external LuaLibName;
   638   cdecl; external LuaLibName;
       
   639 
   679 
   640 procedure luaL_where(L : Plua_State; lvl : LongInt);
   680 procedure luaL_where(L : Plua_State; lvl : LongInt);
   641   cdecl; external LuaLibName;
   681     cdecl; external LuaLibName;
   642 function  luaL_error(L : Plua_State; const fmt : PChar) : LongInt; varargs;
   682 function  luaL_error(L : Plua_State; const fmt : PChar) : LongInt; varargs;
   643   cdecl; external LuaLibName;
   683     cdecl; external LuaLibName;
   644 
   684 
   645 function luaL_checkoption(L : Plua_State; narg : LongInt; const def : PChar;
   685 function luaL_checkoption(L : Plua_State; narg : LongInt; const def : PChar; const lst : array of PChar) : LongInt;
   646                           const lst : array of PChar) : LongInt;
   686     cdecl; external LuaLibName;
   647   cdecl; external LuaLibName;
       
   648 
   687 
   649 function  luaL_ref(L : Plua_State; t : LongInt) : LongInt;
   688 function  luaL_ref(L : Plua_State; t : LongInt) : LongInt;
   650   cdecl; external LuaLibName;
   689     cdecl; external LuaLibName;
   651 procedure luaL_unref(L : Plua_State; t, ref : LongInt);
   690 procedure luaL_unref(L : Plua_State; t, ref : LongInt);
   652   cdecl; external LuaLibName;
   691     cdecl; external LuaLibName;
   653 
   692 
   654 function luaL_loadfile(L : Plua_State; const filename : PChar) : LongInt;
   693 function luaL_loadfile(L : Plua_State; const filename : PChar) : LongInt;
   655   cdecl; external LuaLibName;
   694     cdecl; external LuaLibName;
   656 function luaL_loadbuffer(L : Plua_State; const buff : PChar;
   695 function luaL_loadbuffer(L : Plua_State; const buff : PChar; sz : size_t; const name: PChar) : LongInt;
   657                          sz : size_t; const name: PChar) : LongInt;
   696     cdecl; external LuaLibName;
   658   cdecl; external LuaLibName;
       
   659 
   697 
   660 function luaL_loadstring(L : Plua_State; const s : Pchar) : LongInt;
   698 function luaL_loadstring(L : Plua_State; const s : Pchar) : LongInt;
   661   cdecl; external LuaLibName;
   699     cdecl; external LuaLibName;
   662 
   700 
   663 function luaL_newstate : Plua_State;
   701 function luaL_newstate : Plua_State;
   664   cdecl; external LuaLibName;
   702     cdecl; external LuaLibName;
   665 
   703 
   666 function luaL_gsub(L : Plua_State; const s, p, r : PChar) : PChar;
   704 function luaL_gsub(L : Plua_State; const s, p, r : PChar) : PChar;
   667   cdecl; external LuaLibName;
   705     cdecl; external LuaLibName;
   668 
   706 
   669 function luaL_findtable(L : Plua_State; idx : LongInt;
   707 function luaL_findtable(L : Plua_State; idx : LongInt; const fname : PChar; szhint : LongInt) : PChar;
   670                         const fname : PChar; szhint : LongInt) : PChar;
   708     cdecl; external LuaLibName;
   671   cdecl; external LuaLibName;
       
   672 
   709 
   673 
   710 
   674 (*
   711 (*
   675 ** ===============================================================
   712 ** ===============================================================
   676 ** some useful macros
   713 ** some useful macros
   677 ** ===============================================================
   714 ** ===============================================================
   678 *)
   715 *)
   679 
   716 
   680 function luaL_argcheck(L : Plua_State; cond : Boolean; numarg : LongInt;
   717 function luaL_argcheck(L : Plua_State; cond : Boolean; numarg : LongInt; extramsg : PChar): LongInt;
   681                        extramsg : PChar): LongInt;
       
   682 function luaL_checkstring(L : Plua_State; n : LongInt) : PChar;
   718 function luaL_checkstring(L : Plua_State; n : LongInt) : PChar;
   683 function luaL_optstring(L : Plua_State; n : LongInt; d : PChar) : PChar;
   719 function luaL_optstring(L : Plua_State; n : LongInt; d : PChar) : PChar;
   684 function luaL_checkint(L : Plua_State; n : LongInt) : lua_Integer;
   720 function luaL_checkint(L : Plua_State; n : LongInt) : lua_Integer;
   685 function luaL_optint(L : Plua_State; n : LongInt; d : lua_Integer): lua_Integer;
   721 function luaL_optint(L : Plua_State; n : LongInt; d : lua_Integer): lua_Integer;
   686 function luaL_checklong(L : Plua_State; n : LongInt) : lua_Integer;
   722 function luaL_checklong(L : Plua_State; n : LongInt) : lua_Integer;
   703 ** Generic Buffer manipulation
   739 ** Generic Buffer manipulation
   704 ** =======================================================
   740 ** =======================================================
   705 *)
   741 *)
   706 
   742 
   707 type
   743 type
   708   luaL_Buffer = packed record
   744     luaL_Buffer = packed record
   709     p : PChar;       (* current position in buffer *)
   745     p : PChar;       (* current position in buffer *)
   710     lvl : LongInt;   (* number of strings in the stack (level) *)
   746     lvl : LongInt;   (* number of strings in the stack (level) *)
   711     L : Plua_State;
   747     L : Plua_State;
   712     buffer : array [0..LUAL_BUFFERSIZE-1] of Char;
   748     buffer : array [0..LUAL_BUFFERSIZE-1] of Char;
   713   end;
   749     end;
   714   PluaL_Buffer = ^luaL_Buffer;
   750     PluaL_Buffer = ^luaL_Buffer;
   715 
   751 
   716 procedure luaL_addchar(B : PluaL_Buffer; c : Char);
   752 procedure luaL_addchar(B : PluaL_Buffer; c : Char);
   717 
   753 
   718 (* compatibility only *)
   754 (* compatibility only *)
   719 procedure luaL_putchar(B : PluaL_Buffer; c : Char);
   755 procedure luaL_putchar(B : PluaL_Buffer; c : Char);
   720 
   756 
   721 procedure luaL_addsize(B : PluaL_Buffer; n : LongInt);
   757 procedure luaL_addsize(B : PluaL_Buffer; n : LongInt);
   722 
   758 
   723 procedure luaL_buffinit(L : Plua_State; B : PluaL_Buffer);
   759 procedure luaL_buffinit(L : Plua_State; B : PluaL_Buffer);
   724   cdecl; external LuaLibName;
   760     cdecl; external LuaLibName;
   725 function  luaL_prepbuffer(B : PluaL_Buffer) : PChar;
   761 function  luaL_prepbuffer(B : PluaL_Buffer) : PChar;
   726   cdecl; external LuaLibName;
   762     cdecl; external LuaLibName;
   727 procedure luaL_addlstring(B : PluaL_Buffer; const s : PChar; ls : size_t);
   763 procedure luaL_addlstring(B : PluaL_Buffer; const s : PChar; ls : size_t);
   728   cdecl; external LuaLibName;
   764     cdecl; external LuaLibName;
   729 procedure luaL_addstring(B : PluaL_Buffer; const s : PChar);
   765 procedure luaL_addstring(B : PluaL_Buffer; const s : PChar);
   730   cdecl; external LuaLibName;
   766     cdecl; external LuaLibName;
   731 procedure luaL_addvalue(B : PluaL_Buffer);
   767 procedure luaL_addvalue(B : PluaL_Buffer);
   732   cdecl; external LuaLibName;
   768     cdecl; external LuaLibName;
   733 procedure luaL_pushresult(B : PluaL_Buffer);
   769 procedure luaL_pushresult(B : PluaL_Buffer);
   734   cdecl; external LuaLibName;
   770     cdecl; external LuaLibName;
   735 
   771 
   736 (* ====================================================== *)
   772 (* ====================================================== *)
   737 
   773 
   738 
   774 
   739 (* compatibility with ref system *)
   775 (* compatibility with ref system *)
   740 
   776 
   741 (* pre-defined references *)
   777 (* pre-defined references *)
   742 const
   778 const
   743   LUA_NOREF  = -2;
   779     LUA_NOREF  = -2;
   744   LUA_REFNIL = -1;
   780     LUA_REFNIL = -1;
   745 
   781 
   746 function lua_ref(L : Plua_State; lock : Boolean) : LongInt;
   782 function lua_ref(L : Plua_State; lock : Boolean) : LongInt;
   747 
   783 
   748 procedure lua_unref(L : Plua_State; ref : LongInt);
   784 procedure lua_unref(L : Plua_State; ref : LongInt);
   749 
   785 
   761 
   797 
   762 (*****************************************************************************)
   798 (*****************************************************************************)
   763 (*                            luaconfig.h                                    *)
   799 (*                            luaconfig.h                                    *)
   764 (*****************************************************************************)
   800 (*****************************************************************************)
   765 
   801 
   766 function  lua_readline(L : Plua_State; var b : PChar; p : PChar): Boolean;
   802 function  lua_readline(L : Plua_State;
   767 var
   803 var
   768   s : AnsiString;
   804     b : PChar; p : PChar): Boolean;
   769 begin
   805 var
   770   Write(p);                        // show prompt
   806     s : AnsiString;
   771   ReadLn(s);                       // get line
   807 begin
   772   b := PChar(s);                   //   and return it
   808     Write(p);                        // show prompt
   773   lua_readline := (b[0] <> #4);          // test for ctrl-D
   809     ReadLn(s);                       // get line
       
   810     b := PChar(s);                   //   and return it
       
   811     lua_readline := (b[0] <> #4);          // test for ctrl-D
   774 end;
   812 end;
   775 
   813 
   776 procedure lua_saveline(L : Plua_State; idx : LongInt);
   814 procedure lua_saveline(L : Plua_State; idx : LongInt);
   777 begin
   815 begin
   778 end;
   816 end;
   786 (*                                  lua.h                                    *)
   824 (*                                  lua.h                                    *)
   787 (*****************************************************************************)
   825 (*****************************************************************************)
   788 
   826 
   789 function lua_upvalueindex(idx : LongInt) : LongInt;
   827 function lua_upvalueindex(idx : LongInt) : LongInt;
   790 begin
   828 begin
   791   lua_upvalueindex := LUA_GLOBALSINDEX - idx;
   829 lua_upvalueindex := LUA_GLOBALSINDEX - idx;
   792 end;
   830 end;
   793 
   831 
   794 procedure lua_pop(L : Plua_State; n : LongInt);
   832 procedure lua_pop(L : Plua_State; n : LongInt);
   795 begin
   833 begin
   796   lua_settop(L, -n - 1);
   834 lua_settop(L, -n - 1);
   797 end;
   835 end;
   798 
   836 
   799 procedure lua_newtable(L : Plua_State);
   837 procedure lua_newtable(L : Plua_State);
   800 begin
   838 begin
   801   lua_createtable(L, 0, 0);
   839 lua_createtable(L, 0, 0);
   802 end;
   840 end;
   803 
   841 
   804 procedure lua_register(L : Plua_State; n : PChar; f : lua_CFunction);
   842 procedure lua_register(L : Plua_State; n : PChar; f : lua_CFunction);
   805 begin
   843 begin
   806   lua_pushcfunction(L, f);
   844 lua_pushcfunction(L, f);
   807   lua_setglobal(L, n);
   845 lua_setglobal(L, n);
   808 end;
   846 end;
   809 
   847 
   810 procedure lua_pushcfunction(L : Plua_State; f : lua_CFunction);
   848 procedure lua_pushcfunction(L : Plua_State; f : lua_CFunction);
   811 begin
   849 begin
   812   lua_pushcclosure(L, f, 0);
   850     lua_pushcclosure(L, f, 0);
   813 end;
   851 end;
   814 
   852 
   815 function  lua_strlen(L : Plua_State; idx : LongInt) : LongInt;
   853 function  lua_strlen(L : Plua_State; idx : LongInt) : LongInt;
   816 begin
   854 begin
   817   lua_strlen := lua_objlen(L, idx);
   855     lua_strlen := lua_objlen(L, idx);
   818 end;
   856 end;
   819 
   857 
   820 function lua_isfunction(L : Plua_State; n : LongInt) : Boolean;
   858 function lua_isfunction(L : Plua_State; n : LongInt) : Boolean;
   821 begin
   859 begin
   822   lua_isfunction := lua_type(L, n) = LUA_TFUNCTION;
   860     lua_isfunction := lua_type(L, n) = LUA_TFUNCTION;
   823 end;
   861 end;
   824 
   862 
   825 function lua_istable(L : Plua_State; n : LongInt) : Boolean;
   863 function lua_istable(L : Plua_State; n : LongInt) : Boolean;
   826 begin
   864 begin
   827   lua_istable := lua_type(L, n) = LUA_TTABLE;
   865     lua_istable := lua_type(L, n) = LUA_TTABLE;
   828 end;
   866 end;
   829 
   867 
   830 function lua_islightuserdata(L : Plua_State; n : LongInt) : Boolean;
   868 function lua_islightuserdata(L : Plua_State; n : LongInt) : Boolean;
   831 begin
   869 begin
   832   lua_islightuserdata := lua_type(L, n) = LUA_TLIGHTUSERDATA;
   870     lua_islightuserdata := lua_type(L, n) = LUA_TLIGHTUSERDATA;
   833 end;
   871 end;
   834 
   872 
   835 function lua_isnil(L : Plua_State; n : LongInt) : Boolean;
   873 function lua_isnil(L : Plua_State; n : LongInt) : Boolean;
   836 begin
   874 begin
   837   lua_isnil := lua_type(L, n) = LUA_TNIL;
   875     lua_isnil := lua_type(L, n) = LUA_TNIL;
   838 end;
   876 end;
   839 
   877 
   840 function lua_isboolean(L : Plua_State; n : LongInt) : Boolean;
   878 function lua_isboolean(L : Plua_State; n : LongInt) : Boolean;
   841 begin
   879 begin
   842   lua_isboolean := lua_type(L, n) = LUA_TBOOLEAN;
   880     lua_isboolean := lua_type(L, n) = LUA_TBOOLEAN;
   843 end;
   881 end;
   844 
   882 
   845 function lua_isthread(L : Plua_State; n : LongInt) : Boolean;
   883 function lua_isthread(L : Plua_State; n : LongInt) : Boolean;
   846 begin
   884 begin
   847   lua_isthread := lua_type(L, n) = LUA_TTHREAD;
   885     lua_isthread := lua_type(L, n) = LUA_TTHREAD;
   848 end;
   886 end;
   849 
   887 
   850 function lua_isnone(L : Plua_State; n : LongInt) : Boolean;
   888 function lua_isnone(L : Plua_State; n : LongInt) : Boolean;
   851 begin
   889 begin
   852   lua_isnone := lua_type(L, n) = LUA_TNONE;
   890     lua_isnone := lua_type(L, n) = LUA_TNONE;
   853 end;
   891 end;
   854 
   892 
   855 function lua_isnoneornil(L : Plua_State; n : LongInt) : Boolean;
   893 function lua_isnoneornil(L : Plua_State; n : LongInt) : Boolean;
   856 begin
   894 begin
   857   lua_isnoneornil := lua_type(L, n) <= 0;
   895     lua_isnoneornil := lua_type(L, n) <= 0;
   858 end;
   896 end;
   859 
   897 
   860 procedure lua_pushliteral(L : Plua_State; s : PChar);
   898 procedure lua_pushliteral(L : Plua_State; s : PChar);
   861 begin
   899 begin
   862   lua_pushlstring(L, s, StrLen(s));
   900     lua_pushlstring(L, s, StrLen(s));
   863 end;
   901 end;
   864 
   902 
   865 procedure lua_setglobal(L : Plua_State; s : PChar);
   903 procedure lua_setglobal(L : Plua_State; s : PChar);
   866 begin
   904 begin
   867   lua_setfield(L, LUA_GLOBALSINDEX, s);
   905     lua_setfield(L, LUA_GLOBALSINDEX, s);
   868 end;
   906 end;
   869 
   907 
   870 procedure lua_getglobal(L: Plua_State; s: PChar);
   908 procedure lua_getglobal(L: Plua_State; s: PChar);
   871 begin
   909 begin
   872   lua_getfield(L, LUA_GLOBALSINDEX, s);
   910     lua_getfield(L, LUA_GLOBALSINDEX, s);
   873 end;
   911 end;
   874 
   912 
   875 function lua_tostring(L : Plua_State; idx : LongInt) : AnsiString;
   913 function lua_tostring(L : Plua_State; idx : LongInt) : AnsiString;
   876 begin
   914 begin
   877   lua_tostring := SysUtils.StrPas(lua_tolstring(L, idx, nil));
   915     lua_tostring := SysUtils.StrPas(lua_tolstring(L, idx, nil));
   878 end;
   916 end;
   879 
   917 
   880 function lua_open : Plua_State;
   918 function lua_open : Plua_State;
   881 begin
   919 begin
   882   lua_open := luaL_newstate;
   920     lua_open := luaL_newstate;
   883 end;
   921 end;
   884 
   922 
   885 procedure lua_getregistry(L : Plua_State);
   923 procedure lua_getregistry(L : Plua_State);
   886 begin
   924 begin
   887   lua_pushvalue(L, LUA_REGISTRYINDEX);
   925     lua_pushvalue(L, LUA_REGISTRYINDEX);
   888 end;
   926 end;
   889 
   927 
   890 function lua_getgccount(L : Plua_State) : LongInt;
   928 function lua_getgccount(L : Plua_State) : LongInt;
   891 begin
   929 begin
   892   lua_getgccount := lua_gc(L, LUA_GCCOUNT, 0);
   930     lua_getgccount := lua_gc(L, LUA_GCCOUNT, 0);
   893 end;
   931 end;
   894 
   932 
   895 
   933 
   896 (*****************************************************************************)
   934 (*****************************************************************************)
   897 (*                                  lualib.h                                 *)
   935 (*                                  lualib.h                                 *)
   906 (*                                  lauxlib.h    n                           *)
   944 (*                                  lauxlib.h    n                           *)
   907 (*****************************************************************************)
   945 (*****************************************************************************)
   908 
   946 
   909 function luaL_getn(L : Plua_State; idx : LongInt) : LongInt;
   947 function luaL_getn(L : Plua_State; idx : LongInt) : LongInt;
   910 begin
   948 begin
   911   luaL_getn := lua_objlen(L, idx);
   949     luaL_getn := lua_objlen(L, idx);
   912 end;
   950 end;
   913 
   951 
   914 procedure luaL_setn(L : plua_State; i, j : LongInt);
   952 procedure luaL_setn(L : plua_State; i, j : LongInt);
   915 begin
   953 begin
   916   (* no op *)
   954     (* no op *)
   917 end;
   955 end;
   918 
   956 
   919 function luaL_argcheck(L : Plua_State; cond : Boolean; numarg : LongInt;
   957 function luaL_argcheck(L : Plua_State; cond : Boolean; numarg : LongInt; extramsg : PChar): LongInt;
   920                        extramsg : PChar): LongInt;
   958 begin
   921 begin
   959     if not cond then
   922   if not cond then
   960         luaL_argcheck := luaL_argerror(L, numarg, extramsg)
   923     luaL_argcheck := luaL_argerror(L, numarg, extramsg)
   961     else
   924   else
   962         luaL_argcheck := 0;
   925     luaL_argcheck := 0;
       
   926 end;
   963 end;
   927 
   964 
   928 function luaL_checkstring(L : Plua_State; n : LongInt) : PChar;
   965 function luaL_checkstring(L : Plua_State; n : LongInt) : PChar;
   929 begin
   966 begin
   930   luaL_checkstring := luaL_checklstring(L, n, nil);
   967     luaL_checkstring := luaL_checklstring(L, n, nil);
   931 end;
   968 end;
   932 
   969 
   933 function luaL_optstring(L : Plua_State; n : LongInt; d : PChar) : PChar;
   970 function luaL_optstring(L : Plua_State; n : LongInt; d : PChar) : PChar;
   934 begin
   971 begin
   935   luaL_optstring := luaL_optlstring(L, n, d, nil);
   972     luaL_optstring := luaL_optlstring(L, n, d, nil);
   936 end;
   973 end;
   937 
   974 
   938 function luaL_checkint(L : Plua_State; n : LongInt) : lua_Integer;
   975 function luaL_checkint(L : Plua_State; n : LongInt) : lua_Integer;
   939 begin
   976 begin
   940   luaL_checkint := luaL_checkinteger(L, n);
   977     luaL_checkint := luaL_checkinteger(L, n);
   941 end;
   978 end;
   942 
   979 
   943 function luaL_optint(L : Plua_State; n : LongInt; d : lua_Integer): lua_Integer;
   980 function luaL_optint(L : Plua_State; n : LongInt; d : lua_Integer): lua_Integer;
   944 begin
   981 begin
   945   luaL_optint := luaL_optinteger(L, n, d);
   982     luaL_optint := luaL_optinteger(L, n, d);
   946 end;
   983 end;
   947 
   984 
   948 function luaL_checklong(L : Plua_State; n : LongInt) : lua_Integer;
   985 function luaL_checklong(L : Plua_State; n : LongInt) : lua_Integer;
   949 begin
   986 begin
   950   luaL_checklong := luaL_checkinteger(L, n);
   987     luaL_checklong := luaL_checkinteger(L, n);
   951 end;
   988 end;
   952 
   989 
   953 function luaL_optlong(L : Plua_State; n : LongInt; d : lua_Integer) : lua_Integer;
   990 function luaL_optlong(L : Plua_State; n : LongInt; d : lua_Integer) : lua_Integer;
   954 begin
   991 begin
   955   luaL_optlong := luaL_optinteger(L, n, d);
   992     luaL_optlong := luaL_optinteger(L, n, d);
   956 end;
   993 end;
   957 
   994 
   958 function luaL_typename(L : Plua_State; idx : LongInt) : PChar;
   995 function luaL_typename(L : Plua_State; idx : LongInt) : PChar;
   959 begin
   996 begin
   960   luaL_typename := lua_typename( L, lua_type(L, idx) );
   997     luaL_typename := lua_typename( L, lua_type(L, idx) );
   961 end;
   998 end;
   962 
   999 
   963 function luaL_dofile(L : Plua_State; fn : PChar) : LongInt;
  1000 function luaL_dofile(L : Plua_State; fn : PChar) : LongInt;
   964 begin
  1001 begin
   965   luaL_dofile := luaL_loadfile(L, fn);
  1002     luaL_dofile := luaL_loadfile(L, fn);
   966   if luaL_dofile = 0 then
  1003     if luaL_dofile = 0 then
   967     luaL_dofile := lua_pcall(L, 0, 0, 0);
  1004         luaL_dofile := lua_pcall(L, 0, 0, 0);
   968 end;
  1005 end;
   969 
  1006 
   970 function luaL_dostring(L : Plua_State; s : PChar) : LongInt;
  1007 function luaL_dostring(L : Plua_State; s : PChar) : LongInt;
   971 begin
  1008 begin
   972   luaL_dostring := luaL_loadstring(L, s);
  1009     luaL_dostring := luaL_loadstring(L, s);
   973   if luaL_dostring = 0 then
  1010     if luaL_dostring = 0 then
   974     luaL_dostring := lua_pcall(L, 0, 0, 0);
  1011         luaL_dostring := lua_pcall(L, 0, 0, 0);
   975 end;
  1012 end;
   976 
  1013 
   977 procedure luaL_getmetatable(L : Plua_State; n : PChar);
  1014 procedure luaL_getmetatable(L : Plua_State; n : PChar);
   978 begin
  1015 begin
   979   lua_getfield(L, LUA_REGISTRYINDEX, n);
  1016     lua_getfield(L, LUA_REGISTRYINDEX, n);
   980 end;
  1017 end;
   981 
  1018 
   982 procedure luaL_addchar(B : PluaL_Buffer; c : Char);
  1019 procedure luaL_addchar(B : PluaL_Buffer; c : Char);
   983 begin
  1020 begin
   984   if not(B^.p < B^.buffer + LUAL_BUFFERSIZE) then
  1021     if not(B^.p < B^.buffer + LUAL_BUFFERSIZE) then
   985     luaL_prepbuffer(B);
  1022         luaL_prepbuffer(B);
   986   (B^.p^) := c;
  1023     (B^.p^) := c;
   987   Inc(B^.p);
  1024     Inc(B^.p);
   988 end;
  1025 end;
   989 
  1026 
   990 procedure luaL_putchar(B : PluaL_Buffer; c : Char);
  1027 procedure luaL_putchar(B : PluaL_Buffer; c : Char);
   991 begin
  1028 begin
   992   luaL_addchar(B, c);
  1029     luaL_addchar(B, c);
   993 end;
  1030 end;
   994 
  1031 
   995 procedure luaL_addsize(B : PluaL_Buffer; n : LongInt);
  1032 procedure luaL_addsize(B : PluaL_Buffer; n : LongInt);
   996 begin
  1033 begin
   997   Inc(B^.p, n);
  1034   Inc(B^.p, n);
   998 end;
  1035 end;
   999 
  1036 
  1000 function lua_ref(L : Plua_State; lock : Boolean) : LongInt;
  1037 function lua_ref(L : Plua_State; lock : Boolean) : LongInt;
  1001 begin
  1038 begin
  1002   if lock then
  1039     if lock then
  1003     lua_ref := luaL_ref(L, LUA_REGISTRYINDEX)
  1040         lua_ref := luaL_ref(L, LUA_REGISTRYINDEX)
  1004   else begin
  1041     else
  1005     lua_pushstring(L, 'unlocked references are obsolete');
  1042         begin
  1006     lua_error(L);
  1043         lua_pushstring(L, 'unlocked references are obsolete');
  1007     lua_ref := 0;
  1044         lua_error(L);
  1008   end;
  1045         lua_ref := 0;
       
  1046         end;
  1009 end;
  1047 end;
  1010 
  1048 
  1011 procedure lua_unref(L : Plua_State; ref : LongInt);
  1049 procedure lua_unref(L : Plua_State; ref : LongInt);
  1012 begin
  1050 begin
  1013   luaL_unref(L, LUA_REGISTRYINDEX, ref);
  1051     luaL_unref(L, LUA_REGISTRYINDEX, ref);
  1014 end;
  1052 end;
  1015 
  1053 
  1016 procedure lua_getref(L : Plua_State; ref : LongInt);
  1054 procedure lua_getref(L : Plua_State; ref : LongInt);
  1017 begin
  1055 begin
  1018   lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
  1056     lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
  1019 end;
  1057 end;
  1020 
  1058 
  1021 
  1059 
  1022 (******************************************************************************
  1060 (******************************************************************************
  1023 * Original copyright for the lua source and headers:
  1061 * Original copyright for the lua source and headers: