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