首页 > Windows开发 > 详细

delphi调用LUA函数来处理一些逻辑

时间:2017-02-15 16:15:46      阅读:326      评论:0      收藏:0      [点我收藏+]

替同事做了个洛奇英雄传自动染色程序,关于屏幕取色的.

因为里面他对颜色的要求比较复杂,改动也比较大,于是我让他把逻辑写在 lua 脚本里面.

 

 

[delphi] view plain copy
 
  1. uses LUA, LUALIB;  
[delphi] view plain copy
 
  1. function lua_CheckColor(r,g,b:Integer):Boolean;  
  2. var  
  3. Lua : TLua;  
  4. begin  
  5.   Lua := TLua.Create;   
  6.   luaopen_debug(LuaInstance); //如果要使用debug库  
  7. //  luaopen_io(LuaInstance);  
  8.   luaopen_math(LuaInstance);// 如果要使用math库 不然就会attempt to index global ‘math‘ (a nil value)  
  9.   luaopen_os(LuaInstance);  
  10. //  luaopen_package(LuaInstance);  
  11.   luaopen_string(LuaInstance);  
  12.   luaopen_table(LuaInstance);  
  13.   Lua.DoFile(‘lua_GetColor.lua‘);  
  14.   lua_getglobal(Lua.LuaInstance,‘nogi_GetColor‘);  
  15.   lua_pushnumber(Lua.LuaInstance, r); //将脚本中add函数使用的参数压栈  
  16.   lua_pushnumber(Lua.LuaInstance, g); //将脚本中add函数使用的参数压栈  
  17.   lua_pushnumber(Lua.LuaInstance, b); //将脚本中add函数使用的参数压栈  
  18.   
  19.   
  20.   lua_pcall(Lua.LuaInstance, 3, 1,0) ;  
  21.   
  22.   
  23.   Result := (lua_toInteger(Lua.LuaInstance,-1) = 1);  
  24.   Lua.Free;  
  25. end;  


LUA 里面的内容是这样的

 

 

[delphi] view plain copy
 
  1. function nogi_GetColor(nR,nG,nB)  
  2.     if nR <= 25 and nG <= 25 and nB <= 25 then -- 取出25以下黑色  
  3.         return 1;  
  4.     end;  
  5.       
  6.     return 0;  
  7. end  



 

 

 

 

 

附上我这里带的 LUA.PAS 和 LUALIB.PAS

lua.pas

 

[delphi] view plain copy
 
  1. { 
  2. /** 
  3.  * @package     Delphi Lua 
  4.  * @copyright   Copyright (c) 2009 Dennis D. Spreen (http://www.spreendigital.de/blog) 
  5.  * @license     http://opensource.org/licenses/gpl-license.php GNU Public License 
  6.  * @author      Dennis D. Spreen <dennis@spreendigital.de> 
  7.  * @version     1.3 
  8.  * @revision    $Id: Lua.pas 102 2009-09-30 11:39:41Z dennis.spreen $ 
  9.  */ 
  10.  
  11. History 
  12. 1.3     DS      Improved Callback, now uses pointer instead of object index 
  13.                 Modified RegisterFunctions to allow methods from other class 
  14.                 to be registered, moved object table into TLua class 
  15. 1.2 DS  Added example on how to extend lua with a delphi dll 
  16. 1.1     DS      Improved global object table, this optimizes the delphi 
  17.                 function calls 
  18. 1.0     DS      Initial Release 
  19.  
  20. Copyright 2009  Dennis D. Spreen (email : dennis@spreendigital.de) 
  21.  
  22. This program is free software; you can redistribute it and/or modify 
  23. it under the terms of the GNU General Public License as published by 
  24. the Free Software Foundation; either version 2 of the License, or 
  25. (at your option) any later version. 
  26.  
  27. This program is distributed in the hope that it will be useful, 
  28. but WITHOUT ANY WARRANTY; without even the implied warranty of 
  29. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  30. GNU General Public License for more details. 
  31.  
  32. You should have received a copy of the GNU General Public License 
  33. along with this program; if not, write to the Free Software 
  34. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
  35. }  
  36.   
  37. unit Lua;  
  38.   
  39. interface  
  40.   
  41. uses  
  42.   Classes,  
  43.   LuaLib;  
  44.   
  45. type  
  46.   TLuaState = Lua_State;  
  47.   
  48.   TLua = class(TObject)  
  49.   private  
  50.     fAutoRegister: Boolean;  
  51.     CallbackList: TList;  // internal callback list  
  52.   public  
  53.     LuaInstance: TLuaState;  // Lua instance  
  54.     constructor Create(AutoRegister: Boolean = True); overload; virtual;  
  55.     destructor Destroy; override;  
  56.     function DoFile(Filename: String): Integer; virtual;// load file and execute  
  57.     procedure RegisterFunction(FuncName: AnsiString; MethodName: AnsiString = ‘‘; Obj: TObject = NIL); virtual; //register function  
  58.     procedure AutoRegisterFunctions(Obj: TObject);  // register all published functions  
  59.     procedure UnregisterFunctions(Obj: TObject); // unregister all object functions  
  60.   end;  
  61.   
  62. implementation  
  63.   
  64. type  
  65.   TProc = function(L: TLuaState): Integer of object; // Lua Function  
  66.   
  67.   TCallback = class  
  68.     Routine: TMethod;  // Code and Data for the method  
  69.     Exec: TProc;       // Resulting execution function  
  70.   end;  
  71.   
  72. //  
  73. // This function is called by Lua, it extracts the object by  
  74. // pointer to the objects method by name, which is then called.  
  75. //  
  76. // @param       Lua_State   L   Pointer to Lua instance  
  77. // @return      Integer         Number of result arguments on stack  
  78. //  
  79. function LuaCallBack(L: Lua_State): Integer; cdecl;  
  80. var  
  81.   CallBack: TCallBack;       // The Object stored in the Object Table  
  82. begin  
  83.   // Retrieve first Closure Value (=Object Pointer)  
  84.   CallBack := lua_topointer(L, lua_upvalueindex(1));  
  85.   
  86.   // Execute only if Object is valid  
  87.   if (assigned(CallBack) and assigned(CallBack.Exec)) then  
  88.     Result := CallBack.Exec(L)  
  89.   else  
  90.     Result := 0;  
  91. end;  
  92.   
  93. { TLua }  
  94.   
  95. //  
  96. // Create a new Lua instance and optionally create Lua functions  
  97. //  
  98. // @param       Boolean      AutoRegister       (optional)  
  99. // @return      TLua                            Lua Instance  
  100. //  
  101. constructor TLua.Create(AutoRegister: Boolean = True);  
  102. begin  
  103.   inherited Create;  
  104.   // Load Lua Lib if not already done  
  105.   if (not LuaLibLoaded) then  
  106.     LoadLuaLib;  
  107.   
  108.   // Open Library  
  109.   LuaInstance := Lua_Open();  
  110.   luaopen_base(LuaInstance);  
  111.   
  112.   fAutoRegister := AutoRegister;  
  113.   
  114.   // Create Object List on initialization  
  115.   CallBackList := TList.Create;  
  116.   
  117.   // if set then register published functions  
  118.   if (AutoRegister) then  
  119.     AutoRegisterFunctions(self);  
  120. end;  
  121.   
  122. //  
  123. // Dispose Lua instance  
  124. //  
  125. destructor TLua.Destroy;  
  126. begin  
  127.   // Unregister all functions if previously autoregistered  
  128.   if (fAutoRegister) then  
  129.     UnregisterFunctions(Self);  
  130.   
  131.   // dispose Object List on finalization  
  132.   CallBackList.Free;  
  133.   
  134.   // Close instance  
  135.   Lua_Close(LuaInstance);  
  136.   inherited;  
  137. end;  
  138.   
  139. //  
  140. // Wrapper for Lua File load and Execution  
  141. //  
  142. // @param       String  Filename        Lua Script file name  
  143. // @return      Integer  
  144. //  
  145. function TLua.DoFile(Filename: String): Integer;  
  146. begin  
  147.   Result := lual_dofile(LuaInstance, PAnsiChar(AnsiString(Filename)));  
  148. end;  
  149.   
  150. //  
  151. // Register a new Lua Function and map it to the Objects method name  
  152. //  
  153. // @param       AnsiString      FuncName        Lua Function Name  
  154. // @param       AnsiString      MethodName      (optional) Objects Method name  
  155. //  
  156. procedure TLua.RegisterFunction(FuncName: AnsiString; MethodName: AnsiString = ‘‘; Obj: TObject = NIL);  
  157. var  
  158.   CallBack: TCallBack; // Callback Object  
  159. begin  
  160.   // if method name not specified use Lua function name  
  161.   if (MethodName = ‘‘) then  
  162.     MethodName := FuncName;  
  163.   
  164.   // if not object specified use this object  
  165.   if (Obj = NIL) then  
  166.     Obj := Self;  
  167.   
  168.   // Add Callback Object to the Object Index  
  169.   CallBack := TCallBack.Create;  
  170.   CallBack.Routine.Data := Obj;  
  171.   CallBack.Routine.Code := Obj.MethodAddress(String(MethodName));  
  172.   CallBack.Exec := TProc(CallBack.Routine);  
  173.   CallbackList.Add(CallBack);  
  174.   
  175.   // prepare Closure value (Method Name)  
  176.   lua_pushstring(LuaInstance, PAnsiChar(FuncName));  
  177.   
  178.   // prepare Closure value (CallBack Object Pointer)  
  179.   lua_pushlightuserdata(LuaInstance, CallBack);  
  180.   
  181.   // set new Lua function with Closure value  
  182.   lua_pushcclosure(LuaInstance, LuaCallBack, 1);  
  183.   lua_settable(LuaInstance, LUA_GLOBALSINDEX);  
  184. end;  
  185.   
  186. //  
  187. // UnRegister all new Lua Function  
  188. //  
  189. // @param       TObject     Object      Object with prev registered lua functions  
  190. //  
  191. procedure TLua.UnregisterFunctions(Obj: TObject);  
  192. var  
  193.   I: Integer;  
  194.   CallBack: TCallBack;  
  195. begin  
  196.   // remove obj from object list  
  197.   for I := CallBackList.Count downto 1 do  
  198.   begin  
  199.     CallBack := CallBackList[I-1];  
  200.     if (assigned(CallBack)) and (CallBack.Routine.Data = Obj) then  
  201.     begin  
  202.       CallBack.Free;  
  203.       CallBackList.Items[I-1] := NIL;  
  204.       CallBackList.Delete(I-1);  
  205.     end;  
  206.   end;  
  207. end;  
  208.   
  209. //  
  210. // Register all published methods as Lua Functions  
  211. //  
  212. procedure TLua.AutoRegisterFunctions(Obj: TObject);  
  213. type  
  214.   PPointer = ^Pointer;  
  215.   PMethodRec = ^TMethodRec;  
  216.   
  217.   TMethodRec = packed record  
  218.     wSize: Word;  
  219.     pCode: Pointer;  
  220.     sName: ShortString;  
  221.   end;  
  222. var  
  223.   MethodTable: PAnsiChar;  
  224.   MethodRec: PMethodRec;  
  225.   wCount: Word;  
  226.   nMethod: Integer;  
  227. begin  
  228.   // Get a pointer to the class‘s published method table  
  229.   MethodTable := PAnsiChar(Pointer(PAnsiChar(Obj.ClassType) + vmtMethodTable)^);  
  230.   
  231.   if (MethodTable <> Nil) then  
  232.   begin  
  233.     // Get the count of the methods in the table  
  234.     Move(MethodTable^, wCount, 2);  
  235.   
  236.     // Position the MethodRec pointer at the first method in the table  
  237.     // (skip over the 2-byte method count)  
  238.     MethodRec := PMethodRec(MethodTable + 2);  
  239.   
  240.     // Iterate through all the published methods of this class  
  241.     for nMethod := 0 to wCount - 1 do  
  242.     begin  
  243.       // Add the method name to the lua functions  
  244.       RegisterFunction(MethodRec.sName, MethodRec.sName, Obj);  
  245.       // Skip to the next method  
  246.       MethodRec := PMethodRec(PAnsiChar(MethodRec) + MethodRec.wSize);  
  247.     end;  
  248.   end;  
  249. end;  
  250.   
  251.   
  252. end.  



 

 

lualib.pas

 

[delphi] view plain copy
 
    1. (****************************************************************************** 
    2. * Original copyright for the lua source and headers: 
    3. *  1994-2004 Tecgraf, PUC-Rio. 
    4. *  www.lua.org. 
    5. * 
    6. * Copyright for the Delphi adaptation: 
    7. *  2005 Rolf Meyerhoff 
    8. *  www.matrix44.de 
    9. * 
    10. * Copyright for the Lua 5.1 adaptation: 
    11. *  2007 Marco Antonio Abreu 
    12. *  www.marcoabreu.eti.br 
    13. * 
    14. *  All rights reserved. 
    15. * 
    16. * Permission is hereby granted, free of charge, to any person obtaining 
    17. * a copy of this software and associated documentation files (the 
    18. * "Software"), to deal in the Software without restriction, including 
    19. * without limitation the rights to use, copy, modify, merge, publish, 
    20. * distribute, sublicense, and/or sell copies of the Software, and to 
    21. * permit persons to whom the Software is furnished to do so, subject to 
    22. * the following conditions: 
    23. * 
    24. * The above copyright notice and this permission notice shall be 
    25. * included in all copies or substantial portions of the Software. 
    26. * 
    27. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
    28. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
    29. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
    30. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 
    31. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
    32. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
    33. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
    34. ******************************************************************************)  
    35. unit LuaLib;  
    36.   
    37. interface  
    38.   
    39. const  
    40.   LUA_VERSION   = ‘Lua 5.1‘;  
    41.   LUA_RELEASE   = ‘Lua 5.1.2‘;  
    42.   LUA_COPYRIGHT = ‘Copyright (C) 1994-2004 Tecgraf, PUC-Rio‘;  
    43.   LUA_AUTHORS   = ‘R. Ierusalimschy, L. H. de Figueiredo & W. Celes‘;  
    44.   
    45.   LUA_PASCAL_51_AUTHOR = ‘Marco Antonio Abreu‘;  
    46.   LUA_PASCAL_51_COPYRIGHT = ‘Copyright (C) 2007 Marco Antonio Abreu‘;  
    47.   
    48.   (* mark for precompiled code (`<esc>Lua‘) *)  
    49.   LUA_SIGNATURE = #27‘Lua‘;  
    50.   
    51.   (* option for multiple returns in `lua_pcall‘ and `lua_call‘ *)  
    52.   LUA_MULTRET   = -1;  
    53.   
    54.   (* 
    55.   ** pseudo-indices 
    56.   *)  
    57.   LUA_REGISTRYINDEX = -10000;  
    58.   LUA_ENVIRONINDEX  = -10001;  
    59.   LUA_GLOBALSINDEX  = -10002;  
    60.   
    61.   (* thread status; 0 is OK *)  
    62.   LUA_TRD_YIELD = 1;  
    63.   LUA_ERRRUN    = 2;  
    64.   LUA_ERRSYNTAX = 3;  
    65.   LUA_ERRMEM    = 4;  
    66.   LUA_ERRERR    = 5;  
    67.   
    68.   (* extra error code for `luaL_load‘ *)  
    69.   LUA_ERRFILE   = LUA_ERRERR + 1;  
    70.   
    71.   (* 
    72.   ** basic types 
    73.   *)  
    74.   LUA_TNONE          = -1;  
    75.   LUA_TNIL           = 0;  
    76.   LUA_TBOOLEAN       = 1;  
    77.   LUA_TLIGHTUSERDATA = 2;  
    78.   LUA_TNUMBER        = 3;  
    79.   LUA_TSTRING        = 4;  
    80.   LUA_TTABLE         = 5;  
    81.   LUA_TFUNCTION      = 6;  
    82.   LUA_TUSERDATA      = 7;  
    83.   LUA_TTHREAD        = 8;  
    84.   
    85.   (* minimum Lua stack available to a C function *)  
    86.   LUA_MINSTACK       = 20;  
    87.   
    88.   (* 
    89.   ** garbage-collection function and options 
    90.   *)  
    91.   LUA_GCSTOP        = 0;  
    92.   LUA_GCRESTART     = 1;  
    93.   LUA_GCCOLLECT     = 2;  
    94.   LUA_GCCOUNT       = 3;  
    95.   LUA_GCCOUNTB      = 4;  
    96.   LUA_GCSTEP        = 5;  
    97.   LUA_GCSETPAUSE    = 6;  
    98.   LUA_GCSETSTEPMUL  = 7;  
    99.   
    100.   (* 
    101.   ** {====================================================================== 
    102.   ** Debug API 
    103.   ** ======================================================================= 
    104.   *)  
    105.   
    106.   (* 
    107.   ** Event codes 
    108.   *)  
    109.   LUA_HOOKCALL    = 0;  
    110.   LUA_HOOKRET     = 1;  
    111.   LUA_HOOKLINE    = 2;  
    112.   LUA_HOOKCOUNT   = 3;  
    113.   LUA_HOOKTAILRET = 4;  
    114.   
    115.   (* 
    116.   ** Event masks 
    117.   *)  
    118.   LUA_MASKCALL  = (1 shl LUA_HOOKCALL);  
    119.   LUA_MASKRET   = (1 shl LUA_HOOKRET);  
    120.   LUA_MASKLINE  = (1 shl LUA_HOOKLINE);  
    121.   LUA_MASKCOUNT = (1 shl LUA_HOOKCOUNT);  
    122.   
    123.   (* 
    124.   ** {====================================================================== 
    125.   ** useful definitions for Lua kernel and libraries 
    126.   ** ======================================================================= 
    127.   *)  
    128.   
    129.   (* 
    130.   @@ LUA_NUMBER_SCAN is the format for reading numbers. 
    131.   @@ LUA_NUMBER_FMT is the format for writing numbers. 
    132.   @@ lua_number2str converts a number to a string. 
    133.   @@ LUAI_MAXNUMBER2STR is maximum size of previous conversion. 
    134.   @@ lua_str2number converts a string to a number. 
    135.   *)  
    136.   LUA_NUMBER_SCAN   =   ‘%lf‘;  
    137.   LUA_NUMBER_FMT     =  ‘%.14g‘;  
    138.   LUAI_MAXNUMBER2STR =  32;  (* 16 digits, sign, point, and \0 *)  
    139.   
    140.   (* pre-defined references *)  
    141.   LUA_NOREF  = -2;  
    142.   LUA_REFNIL = -1;  
    143.   
    144.   LUA_IDSIZE = 60;  
    145.   
    146.   (* 
    147.   ** package names 
    148.   *)  
    149.   LUA_COLIBNAME   = ‘coroutine‘;  
    150.   LUA_TABLIBNAME  = ‘table‘;  
    151.   LUA_IOLIBNAME   = ‘io‘;  
    152.   LUA_OSLIBNAME   = ‘os‘;  
    153.   LUA_STRLIBNAME  = ‘string‘;  
    154.   LUA_MATHLIBNAME = ‘math‘;  
    155.   LUA_DBLIBNAME   = ‘debug‘;  
    156.   LUA_LOADLIBNAME = ‘package‘;  
    157.   
    158.   (* 
    159.   ** {====================================================== 
    160.   ** Generic Buffer manipulation 
    161.   ** ======================================================= 
    162.   *)  
    163.   
    164.   BUFSIZ = 512; (* From stdio.h *)  
    165.   LUAL_BUFFERSIZE = BUFSIZ;  
    166.   
    167. type  
    168.   lua_State = type Pointer;  
    169.   
    170.   lua_CFunction = function(L: lua_State): Integer; cdecl;  
    171.   
    172.   (* 
    173.   ** functions that read/write blocks when loading/dumping Lua chunks 
    174.   *)  
    175.   lua_Reader = function(L: lua_State; data: Pointer; var size: Cardinal): PAnsiChar; cdecl;  
    176.   lua_Writer = function(L: lua_State; p: Pointer; sz: Cardinal; ud: Pointer): Integer; cdecl;  
    177.   
    178.   (* 
    179.   ** prototype for memory-allocation functions 
    180.   *)  
    181.   lua_Alloc = function(ud, ptr: Pointer; osize, nsize: Cardinal): Pointer; cdecl;  
    182.   
    183.   (* type of numbers in Lua *)  
    184.   lua_Number  = type double;  
    185.   (* type for integer functions *)  
    186.   lua_Integer = type integer;  
    187.   
    188.   lua_Debug = packed record  
    189.     event: Integer;  
    190.     name: PAnsiChar; (* (n) *)  
    191.     namewhat: PAnsiChar; (* (n) `global‘, `local‘, `field‘, `method‘ *)  
    192.     what: PAnsiChar; (* (S) `Lua‘, `C‘, `main‘, `tail‘ *)  
    193.     source: PAnsiChar; (* (S) *)  
    194.     currentline: Integer; (* (l) *)  
    195.     nups: Integer;  (* (u) number of upvalues *)  
    196.     linedefined: Integer; (* (S) *)  
    197.     lastlinedefine: Integer;    (* (S) *)  
    198.     short_src: array[0..LUA_IDSIZE - 1] of AnsiChar; (* (S) *)  
    199.     (* private part *)  
    200.     i_ci: Integer; (* active function *)  
    201.   end;  
    202.   
    203.   (* Functions to be called by the debuger in specific events *)  
    204.   lua_Hook = procedure(L: lua_State; var ar: lua_Debug); cdecl;  
    205.   
    206.   (* Lua Record *)  
    207.   PluaL_reg = ^luaL_reg;  
    208.   luaL_reg = packed record  
    209.     name: PAnsiChar;  
    210.     func: lua_CFunction;  
    211.   end;  
    212.   
    213.   (* 
    214.   ** {====================================================== 
    215.   ** Generic Buffer manipulation 
    216.   ** ======================================================= 
    217.   *)  
    218.   
    219.   luaL_Buffer = packed record  
    220.     p: PAnsiChar; (* current position in buffer *)  
    221.     lvl: Integer;  (* number of strings in the stack (level) *)  
    222.     L: lua_State;  
    223.     buffer: array[0..LUAL_BUFFERSIZE - 1] of AnsiChar;  
    224.   end;  
    225.   
    226. var  
    227.   (* 
    228.   ** state manipulation 
    229.   *)  
    230.   lua_newstate:  function(f: lua_Alloc; ud: Pointer): lua_State; cdecl;  
    231.   lua_close:     procedure(L: lua_State); cdecl;  
    232.   lua_newthread: function(L: lua_State): lua_State; cdecl;  
    233.   lua_atpanic:   function(L: lua_State; panicf: lua_CFunction): lua_CFunction; cdecl;  
    234.   
    235.   (* 
    236.   ** basic stack manipulation 
    237.   *)  
    238.   lua_gettop:     function(L: lua_State): Integer; cdecl;  
    239.   lua_settop:     procedure(L: lua_State; idx: Integer); cdecl;  
    240.   lua_pushvalue:  procedure(L: lua_State; idx: Integer); cdecl;  
    241.   lua_remove:     procedure(L: lua_State; idx: Integer); cdecl;  
    242.   lua_insert:     procedure(L: lua_State; idx: Integer); cdecl;  
    243.   lua_replace:    procedure(L: lua_State; idx: Integer); cdecl;  
    244.   lua_checkstack: function(L: lua_State; extra: Integer): LongBool; cdecl;  
    245.   lua_xmove:      procedure(from, dest: lua_State; n: Integer); cdecl;  
    246.   
    247.   (* 
    248.   ** access functions (stack -> C/Pascal) 
    249.   *)  
    250.   
    251.   lua_isnumber:    function(L: lua_State; idx: Integer): LongBool; cdecl;  
    252.   lua_isstring:    function(L: lua_State; idx: Integer): LongBool; cdecl;  
    253.   lua_iscfunction: function(L: lua_State; idx: Integer): LongBool; cdecl;  
    254.   lua_isuserdata:  function(L: lua_State; idx: Integer): LongBool; cdecl;  
    255.   lua_type:        function(L: lua_State; idx: Integer): Integer; cdecl;  
    256.   lua_typename:    function(L: lua_State; tp: Integer): PAnsiChar; cdecl;  
    257.   
    258.   lua_equal:       function(L: lua_State; idx1, idx2: Integer): LongBool; cdecl;  
    259.   lua_rawequal:    function(L: lua_State; idx1, idx2: Integer): LongBool; cdecl;  
    260.   lua_lessthan:    function(L: lua_State; idx1, idx2: Integer): LongBool; cdecl;  
    261.   
    262.   lua_tonumber:    function(L: lua_State; idx: Integer): lua_Number; cdecl;  
    263.   lua_tointeger:   function(L: lua_State; idx: Integer): lua_Integer; cdecl;  
    264.   lua_toboolean:   function(L: lua_State; idx: Integer): LongBool; cdecl;  
    265.   lua_tolstring:   function(L: lua_State; idx: Integer; var len: Cardinal): PAnsiChar; cdecl;  
    266.   lua_objlen:      function(L: lua_State; idx: Integer): Cardinal; cdecl;  
    267.   lua_tocfunction: function(L: lua_State; idx: Integer): lua_CFunction; cdecl;  
    268.   lua_touserdata:  function(L: lua_State; idx: Integer): Pointer; cdecl;  
    269.   lua_tothread:    function(L: lua_State; idx: Integer): lua_State; cdecl;  
    270.   lua_topointer:   function(L: lua_State; idx: Integer): Pointer; cdecl;  
    271.   
    272.   (* 
    273.   ** push functions (C/Pascal -> stack) 
    274.   *)  
    275.   lua_pushnil:      procedure(L: lua_State); cdecl;  
    276.   lua_pushnumber:   procedure(L: lua_State; n: lua_Number); cdecl;  
    277.   lua_pushinteger:  procedure(L: lua_State; n: lua_Integer); cdecl;  
    278.   lua_pushlstring:  procedure(L: lua_State; s: PAnsiChar; len: Cardinal); cdecl;  
    279.   lua_pushstring:   procedure(L: lua_State; s: PAnsiChar); cdecl;  
    280.   lua_pushvfstring: function(L: lua_State; fmt, argp: PAnsiChar): PAnsiChar; cdecl;  
    281.   
    282.   lua_pushfstring:  function(L: lua_State; fmt: PAnsiChar; args: array of const): PAnsiChar; cdecl;  
    283.   lua_pushcclosure: procedure(L: lua_State; fn: lua_CFunction; n: Integer); cdecl;  
    284.   lua_pushboolean:  procedure(L: lua_State; b: LongBool); cdecl;  
    285.   lua_pushlightuserdata: procedure(L: lua_State; p: Pointer); cdecl;  
    286.   lua_pushthread:   function(L: lua_State): Integer; cdecl;  
    287.   
    288.   (* 
    289.   ** get functions (Lua -> stack) 
    290.   *)  
    291.   lua_gettable:     procedure(L: lua_State; idx: Integer); cdecl;  
    292.   lua_getfield:     procedure(L: lua_State; idx: Integer; k: PAnsiChar); cdecl;  
    293.   lua_rawget:       procedure(L: lua_State; idx: Integer); cdecl;  
    294.   lua_rawgeti:      procedure(L: lua_State; idx, n: Integer); cdecl;  
    295.   lua_createtable:  procedure(L: lua_State; narr, nrec: Integer); cdecl;  
    296.   lua_newuserdata:  function(L: lua_State; size: Cardinal): Pointer; cdecl;  
    297.   lua_getmetatable: function(L: lua_State; idx: Integer): LongBool; cdecl;  
    298.   lua_getfenv:      procedure(L: lua_State; idx: Integer); cdecl;  
    299.   
    300.   (* 
    301.   ** set functions (stack -> Lua) 
    302.   *)  
    303.   lua_settable:     procedure(L: lua_State; idx: Integer); cdecl;  
    304.   lua_setfield:     procedure(L: lua_State; idx: Integer; k: PAnsiChar ); cdecl;  
    305.   lua_rawset:       procedure(L: lua_State; idx: Integer); cdecl;  
    306.   lua_rawseti:      procedure(L: lua_State; idx, n: Integer); cdecl;  
    307.   lua_setmetatable: function(L: lua_State; idx: Integer): LongBool; cdecl;  
    308.   lua_setfenv:      function(L: lua_State; idx: Integer): LongBool; cdecl;  
    309.   
    310.   (* 
    311.   ** `load‘ and `call‘ functions (load and run Lua code) 
    312.   *)  
    313.   lua_call:   procedure(L: lua_State; nargs, nresults: Integer); cdecl;  
    314.   lua_pcall:  function(L: lua_State; nargs, nresults, errfunc: Integer): Integer; cdecl;  
    315.   lua_cpcall: function(L: lua_State; func: lua_CFunction; ud: Pointer): Integer; cdecl;  
    316.   lua_load:   function(L: lua_State; reader: lua_Reader; data: Pointer; chunkname: PAnsiChar): Integer; cdecl;  
    317.   lua_dump:   function(L: lua_State; writer: lua_Writer; data: Pointer): Integer; cdecl;  
    318.   
    319.   (* 
    320.   ** coroutine functions 
    321.   *)  
    322.   lua_yield:  function(L: lua_State; nresults: Integer): Integer; cdecl;  
    323.   lua_resume: function(L: lua_State; narg: Integer): Integer; cdecl;  
    324.   lua_status: function(L: lua_State): Integer; cdecl;  
    325.   
    326.   (* 
    327.   ** garbage-collection functions 
    328.   *)  
    329.   lua_gc: function(L: lua_State; what, data: Integer): Integer; cdecl;  
    330.   
    331.   (* 
    332.   ** miscellaneous functions 
    333.   *)  
    334.   
    335.   lua_error:  function(L: lua_State): Integer; cdecl;  
    336.   lua_next:   function(L: lua_State; idx: Integer): Integer; cdecl;  
    337.   lua_concat: procedure(L: lua_State; n: Integer); cdecl;  
    338.   
    339.   lua_getallocf: function(L: lua_State; ud: Pointer): lua_Alloc; cdecl;  
    340.   lua_setallocf: procedure(L: lua_State; f: lua_Alloc; ud: Pointer); cdecl;  
    341.   
    342.   (* 
    343.   ** {====================================================================== 
    344.   ** Debug API 
    345.   ** ======================================================================= 
    346.   *)  
    347.   
    348.   lua_getstack:   function(L: lua_State; level: Integer; var ar: lua_Debug): Integer; cdecl;  
    349.   lua_getinfo:    function(L: lua_State; what: PAnsiChar; var ar: lua_Debug): Integer; cdecl;  
    350.   lua_getlocal:   function(L: lua_State; var ar: lua_Debug; n: Integer): PAnsiChar; cdecl;  
    351.   lua_setlocal:   function(L: lua_State; var ar: lua_Debug; n: Integer): PAnsiChar; cdecl;  
    352.   lua_getupvalue: function(L: lua_State; funcindex, n: Integer): PAnsiChar; cdecl;  
    353.   lua_setupvalue: function(L: lua_State; funcindex, n: Integer): PAnsiChar; cdecl;  
    354.   
    355.   lua_sethook:      function(L: lua_State; func: lua_Hook; mask, count: Integer): Integer; cdecl;  
    356.   lua_gethook:      function(L: lua_State): lua_Hook; cdecl;  
    357.   lua_gethookmask:  function(L: lua_State): Integer; cdecl;  
    358.   lua_gethookcount: function(L: lua_State): Integer; cdecl;  
    359.   
    360.   (* lua libraries *)  
    361.   luaopen_base:    function(L: lua_State): Integer; cdecl;  
    362.   luaopen_debug:   function(L: lua_State): Integer; cdecl;  
    363.   luaopen_io:      function(L: lua_State): Integer; cdecl;  
    364.   luaopen_math:    function(L: lua_State): Integer; cdecl;  
    365.   luaopen_os:      function(L: lua_State): Integer; cdecl;  
    366.   luaopen_package: function(L: lua_State): Integer; cdecl;  
    367.   luaopen_string:  function(L: lua_State): Integer; cdecl;  
    368.   luaopen_table:   function(L: lua_State): Integer; cdecl;  
    369.   (* open all previous libraries *)  
    370.   luaL_openlibs:   procedure(L: lua_State); cdecl;  
    371.   
    372.   luaL_register:     procedure(L: lua_State; libname: PAnsiChar; lr: PluaL_reg); cdecl;  
    373.   luaL_getmetafield: function(L: lua_State; obj: Integer; e: PAnsiChar): Integer; cdecl;  
    374.   luaL_callmeta:     function(L: lua_State; obj: Integer; e: PAnsiChar): Integer; cdecl;  
    375.   luaL_typerror:     function(L: lua_State; narg: Integer; tname: PAnsiChar): Integer; cdecl;  
    376.   luaL_argerror:     function(L: lua_State; narg: Integer; extramsg: PAnsiChar): Integer; cdecl;  
    377.   luaL_checklstring: function(L: lua_State; narg: Integer; var len: Cardinal): PAnsiChar; cdecl;  
    378.   luaL_optlstring:   function(L: lua_State; narg: Integer; d: PAnsiChar; var len: Cardinal): PAnsiChar; cdecl;  
    379.   luaL_checknumber:  function(L: lua_State; narg: Integer): lua_Number; cdecl;  
    380.   luaL_optnumber:    function(L: lua_State; narg: Integer; d: lua_Number): lua_Number; cdecl;  
    381.   
    382.   luaL_checkinteger: function(L: lua_State; narg: Integer): lua_Integer; cdecl;  
    383.   luaL_optinteger:   function(L: lua_State; narg: Integer; d: lua_Integer): lua_Integer; cdecl;  
    384.   
    385.   luaL_checkstack: procedure(L: lua_State; sz: Integer; msg: PAnsiChar); cdecl;  
    386.   luaL_checktype:  procedure(L: lua_State; narg, t: Integer); cdecl;  
    387.   luaL_checkany:   procedure(L: lua_State; narg: Integer); cdecl;  
    388.   
    389.   luaL_newmetatable: function(L: lua_State; tname: PAnsiChar): Integer; cdecl;  
    390.   luaL_checkudata:   function(L: lua_State; narg: Integer; tname: PAnsiChar): Pointer; cdecl;  
    391.   
    392.   luaL_checkoption: function(L: lua_State; narg: Integer; def: PAnsiChar; lst: array of PAnsiChar): Integer; cdecl;  
    393.   
    394.   luaL_where: procedure(L: lua_State; lvl: Integer); cdecl;  
    395.   luaL_error: function(L: lua_State; fmt: PAnsiChar; args: array of const): Integer; cdecl;  
    396.   
    397.   luaL_ref:   function(L: lua_State; t: Integer): Integer; cdecl;  
    398.   luaL_unref: procedure(L: lua_State; t, ref: Integer); cdecl;  
    399.   
    400. {$ifdef LUA_COMPAT_GETN}  
    401.   luaL_getn: function(L: lua_State; t: Integer): Integer; cdecl;  
    402.   luaL_setn: procedure(L: lua_State; t, n: Integer); cdecl;  
    403. {$endif}  
    404.   
    405.   luaL_loadfile:   function(L: lua_State; filename: PAnsiChar): Integer; cdecl;  
    406.   luaL_loadbuffer: function(L: lua_State; buff: PAnsiChar; sz: Cardinal; name: PAnsiChar): Integer; cdecl;  
    407.   luaL_loadstring: function(L: lua_State; s: PAnsiChar): Integer; cdecl;  
    408.   
    409.   luaL_newstate:  function(): lua_State; cdecl;  
    410.   luaL_gsub:      function(L: lua_State; s, p, r: PAnsiChar): PAnsiChar; cdecl;  
    411.   luaL_findtable: function(L: lua_State; idx: Integer; fname: PAnsiChar; szhint: Integer): PAnsiChar; cdecl;  
    412.   
    413.   luaL_buffinit:   procedure(L: lua_State; var B: luaL_Buffer); cdecl;  
    414.   luaL_prepbuffer: function(var B: luaL_Buffer): PAnsiChar; cdecl;  
    415.   luaL_addlstring: procedure(var B: luaL_Buffer; s: PAnsiChar; l: Cardinal); cdecl;  
    416.   luaL_addstring:  procedure(var B: luaL_Buffer; s: PAnsiChar); cdecl;  
    417.   luaL_addvalue:   procedure(var B: luaL_Buffer); cdecl;  
    418.   luaL_pushresult: procedure(var B: luaL_Buffer); cdecl;  
    419.   
    420.   (* 
    421.   ** =============================================================== 
    422.   ** some useful macros 
    423.   ** =============================================================== 
    424.   *)  
    425.   
    426. {$ifndef LUA_COMPAT_GETN}  
    427.   function  luaL_getn(L: lua_State; t: Integer): Integer;  
    428.   procedure luaL_setn(L: lua_State; t, n: Integer);   
    429. {$endif}  
    430.   
    431.   (* pseudo-indices *)  
    432.   function lua_upvalueindex(i: Integer): Integer;  
    433.   
    434.   (* to help testing the libraries *)  
    435.   procedure lua_assert(c: Boolean);  
    436.   
    437.   function lua_number2str(s: Lua_Number; n: Integer): String;  
    438.   function lua_str2number(s: String; p: integer): Lua_Number;  
    439.   
    440.   (* argument and parameters checks *)  
    441.   function luaL_argcheck(L: lua_State; cond: Boolean; narg: Integer; extramsg: PAnsiChar): Integer;  
    442.   function luaL_checkstring(L: lua_State; narg: Integer): PAnsiChar;  
    443.   function luaL_optstring(L: lua_State; narg: Integer; d: PAnsiChar): PAnsiChar;  
    444.   function luaL_checkint(L: lua_State; narg: Integer): Integer;  
    445.   function luaL_optint(L: lua_State; narg, d: Integer): Integer;  
    446.   function luaL_checklong(L: lua_State; narg: Integer): LongInt;  
    447.   function luaL_optlong(L: lua_State; narg: Integer; d: LongInt): LongInt;  
    448.   
    449.   function luaL_typename(L: lua_State; idx: Integer): PAnsiChar;  
    450.   function luaL_dofile(L: lua_State; filename: PAnsiChar): Integer;  
    451.   function luaL_dostring(L: lua_State; str: PAnsiChar): Integer;  
    452.   
    453.   procedure luaL_getmetatable(L: lua_State; tname: PAnsiChar);  
    454.   
    455.   (* Generic Buffer manipulation *)  
    456.   procedure luaL_addchar(var B: luaL_Buffer; c: AnsiChar);  
    457.   procedure luaL_putchar(var B: luaL_Buffer; c: AnsiChar);  
    458.   procedure luaL_addsize(var B: luaL_Buffer; n: Cardinal);  
    459.   
    460.   function luaL_check_lstr(L: lua_State; numArg: Integer; var ls: Cardinal): PAnsiChar;  
    461.   function luaL_opt_lstr(L: lua_State; numArg: Integer; def: PAnsiChar; var ls: Cardinal): PAnsiChar;  
    462.   function luaL_check_number(L: lua_State; numArg: Integer): lua_Number;  
    463.   function luaL_opt_number(L: lua_State; nArg: Integer; def: lua_Number): lua_Number;  
    464.   function luaL_arg_check(L: lua_State; cond: Boolean; numarg: Integer; extramsg: PAnsiChar): Integer;  
    465.   function luaL_check_string(L: lua_State; n: Integer): PAnsiChar;  
    466.   function luaL_opt_string(L: lua_State; n: Integer; d: PAnsiChar): PAnsiChar;  
    467.   function luaL_check_int(L: lua_State; n: Integer): Integer;  
    468.   function luaL_check_long(L: lua_State; n: LongInt): LongInt;  
    469.   function luaL_opt_int(L: lua_State; n, d: Integer): Integer;  
    470.   function luaL_opt_long(L: lua_State; n: Integer; d: LongInt): LongInt;  
    471.   
    472.   procedure lua_pop(L: lua_State; n: Integer);  
    473.   procedure lua_newtable(L: lua_State);  
    474.   procedure lua_register(L: lua_state; name: PAnsiChar; f: lua_CFunction);  
    475.   procedure lua_pushcfunction(L: lua_State; f: lua_CFunction);  
    476.   function  lua_strlen(L: lua_State; i: Integer): Cardinal;  
    477.   
    478.   function lua_isfunction(L: lua_State; idx: Integer): Boolean;  
    479.   function lua_istable(L: lua_State; idx: Integer): Boolean;  
    480.   function lua_islightuserdata(L: lua_State; idx: Integer): Boolean;  
    481.   function lua_isnil(L: lua_State; idx: Integer): Boolean;  
    482.   function lua_isboolean(L: lua_State; idx: Integer): Boolean;  
    483.   function lua_isthread(L: lua_State; idx: Integer): Boolean;  
    484.   function lua_isnone(L: lua_State; idx: Integer): Boolean;  
    485.   function lua_isnoneornil(L: lua_State; idx: Integer): Boolean;  
    486.   
    487.   procedure lua_pushliteral(L: lua_State; s: PAnsiChar);  
    488.   procedure lua_setglobal(L: lua_State; name: PAnsiChar);  
    489.   procedure lua_getglobal(L: lua_State; name: PAnsiChar);  
    490.   function  lua_tostring(L: lua_State; idx: Integer): PAnsiChar;  
    491.   
    492.   (* 
    493.   ** compatibility macros and functions 
    494.   *)  
    495.   
    496.   function  lua_open(): lua_State;  
    497.   procedure lua_getregistry(L: lua_State);  
    498.   function  lua_getgccount(L: lua_State): Integer;  
    499.   
    500.   (* compatibility with ref system *)  
    501.   function  lua_ref(L: lua_State; lock: Boolean): Integer;  
    502.   procedure lua_unref(L: lua_State; ref: Integer);  
    503.   procedure lua_getref(L: lua_State; ref: Integer);  
    504.   
    505.   (* 
    506.   ** Dynamic library manipulation 
    507.   *)  
    508.   function  GetProcAddr( fHandle: THandle; const methodName: String; bErrorIfNotExists: Boolean = True ): Pointer;  
    509.   procedure SetLuaLibFileName( newLuaLibFileName: String );  
    510.   function  GetLuaLibFileName(): String;  
    511.   function  LoadLuaLib( newLuaLibFileName: String = ‘‘ ): Integer;  
    512.   procedure FreeLuaLib();  
    513.   function LuaLibLoaded: Boolean;  
    514.   
    515. implementation  
    516.   
    517. uses  
    518.   SysUtils, Math,  
    519. {$ifdef MSWINDOWS}  
    520.   Windows  
    521. {$endif}  
    522. ;  
    523.   
    524. var  
    525.   fLibHandle: Integer = 0;  
    526. {$ifdef MSWINDOWS}  
    527.   fLuaLibFileName: String = ‘Lua5.1.dll‘;  
    528. {$endif}  
    529. {$ifdef LINUX}  
    530.   fLuaLibFileName: String = ‘liblua.so.5.1‘;  
    531. {$endif}  
    532.   
    533. (* 
    534. ** Dynamic library manipulation 
    535. *)  
    536.   
    537. function GetProcAddr( fHandle: THandle; const methodName: String; bErrorIfNotExists: Boolean = True ): Pointer;  
    538. begin  
    539.   Result := GetProcAddress( fHandle, PAnsiChar( AnsiString(methodName) ) );  
    540.   
    541.   if bErrorIfNotExists and ( Result = nil ) then  
    542.      Raise Exception.Create( ‘Cannot load method ‘ + QuotedStr( methodName ) + ‘ from dynamic library.‘ );  
    543. end;  
    544.   
    545. procedure SetLuaLibFileName( newLuaLibFileName: String );  
    546. begin  
    547.   fLuaLibFileName := newLuaLibFileName;  
    548. end;  
    549.   
    550. function GetLuaLibFileName(): String;  
    551. begin  
    552.   Result := fLuaLibFileName;  
    553. end;  
    554.   
    555. function LuaLibLoaded: Boolean;  
    556. begin  
    557.    Result := fLibHandle <> 0;  
    558. end;  
    559.   
    560.   
    561.   
    562. function LoadLuaLib(newLuaLibFileName: String): Integer;  
    563. begin  
    564.   FreeLuaLib();  
    565.   
    566.   if newLuaLibFileName <> ‘‘ then  
    567.      SetLuaLibFileName( newLuaLibFileName );  
    568.   
    569.   if not FileExists( GetLuaLibFileName() ) then begin  
    570.      Result := -1;  
    571.      exit;  
    572.   end;  
    573.   
    574.   fLibHandle := LoadLibrary(PWideChar( (GetLuaLibFileName() ) ));  
    575.   
    576.   if fLibHandle = 0 then begin  
    577.      Result := -2;  
    578.      exit;  
    579.   end;  
    580.   
    581.   lua_newstate       := GetProcAddr( fLibHandle, ‘lua_newstate‘ );  
    582.   lua_close          := GetProcAddr( fLibHandle, ‘lua_close‘ );  
    583.   lua_newthread      := GetProcAddr( fLibHandle, ‘lua_newthread‘ );  
    584.   lua_atpanic        := GetProcAddr( fLibHandle, ‘lua_atpanic‘ );  
    585.   lua_gettop         := GetProcAddr( fLibHandle, ‘lua_gettop‘ );  
    586.   lua_settop         := GetProcAddr( fLibHandle, ‘lua_settop‘ );  
    587.   lua_pushvalue      := GetProcAddr( fLibHandle, ‘lua_pushvalue‘ );  
    588.   lua_remove         := GetProcAddr( fLibHandle, ‘lua_remove‘ );  
    589.   lua_insert         := GetProcAddr( fLibHandle, ‘lua_insert‘ );  
    590.   lua_replace        := GetProcAddr( fLibHandle, ‘lua_replace‘ );  
    591.   lua_checkstack     := GetProcAddr( fLibHandle, ‘lua_checkstack‘ );  
    592.   lua_xmove          := GetProcAddr( fLibHandle, ‘lua_xmove‘ );  
    593.   lua_isnumber       := GetProcAddr( fLibHandle, ‘lua_isnumber‘ );  
    594.   lua_isstring       := GetProcAddr( fLibHandle, ‘lua_isstring‘ );  
    595.   lua_iscfunction    := GetProcAddr( fLibHandle, ‘lua_iscfunction‘ );  
    596.   lua_isuserdata     := GetProcAddr( fLibHandle, ‘lua_isuserdata‘ );  
    597.   lua_type           := GetProcAddr( fLibHandle, ‘lua_type‘ );  
    598.   lua_typename       := GetProcAddr( fLibHandle, ‘lua_typename‘ );  
    599.   lua_equal          := GetProcAddr( fLibHandle, ‘lua_equal‘ );  
    600.   lua_rawequal       := GetProcAddr( fLibHandle, ‘lua_rawequal‘ );  
    601.   lua_lessthan       := GetProcAddr( fLibHandle, ‘lua_lessthan‘ );  
    602.   lua_tonumber       := GetProcAddr( fLibHandle, ‘lua_tonumber‘ );  
    603.   lua_tointeger      := GetProcAddr( fLibHandle, ‘lua_tointeger‘ );  
    604.   lua_toboolean      := GetProcAddr( fLibHandle, ‘lua_toboolean‘ );  
    605.   lua_tolstring      := GetProcAddr( fLibHandle, ‘lua_tolstring‘ );  
    606.   lua_objlen         := GetProcAddr( fLibHandle, ‘lua_objlen‘ );  
    607.   lua_tocfunction    := GetProcAddr( fLibHandle, ‘lua_tocfunction‘ );  
    608.   lua_touserdata     := GetProcAddr( fLibHandle, ‘lua_touserdata‘ );  
    609.   lua_tothread       := GetProcAddr( fLibHandle, ‘lua_tothread‘ );  
    610.   lua_topointer      := GetProcAddr( fLibHandle, ‘lua_topointer‘ );  
    611.   lua_pushnil        := GetProcAddr( fLibHandle, ‘lua_pushnil‘ );  
    612.   lua_pushnumber     := GetProcAddr( fLibHandle, ‘lua_pushnumber‘ );  
    613.   lua_pushinteger    := GetProcAddr( fLibHandle, ‘lua_pushinteger‘ );  
    614.   lua_pushlstring    := GetProcAddr( fLibHandle, ‘lua_pushlstring‘ );  
    615.   lua_pushstring     := GetProcAddr( fLibHandle, ‘lua_pushstring‘ );  
    616.   lua_pushvfstring   := GetProcAddr( fLibHandle, ‘lua_pushvfstring‘ );  
    617.   lua_pushfstring    := GetProcAddr( fLibHandle, ‘lua_pushfstring‘ );  
    618.   lua_pushcclosure   := GetProcAddr( fLibHandle, ‘lua_pushcclosure‘ );  
    619.   lua_pushboolean    := GetProcAddr( fLibHandle, ‘lua_pushboolean‘ );  
    620.   lua_pushlightuserdata := GetProcAddr( fLibHandle, ‘lua_pushlightuserdata‘ );  
    621.   lua_pushthread     := GetProcAddr( fLibHandle, ‘lua_pushthread‘ );  
    622.   lua_gettable       := GetProcAddr( fLibHandle, ‘lua_gettable‘ );  
    623.   lua_getfield       := GetProcAddr( fLibHandle, ‘lua_getfield‘ );  
    624.   lua_rawget         := GetProcAddr( fLibHandle, ‘lua_rawget‘ );  
    625.   lua_rawgeti        := GetProcAddr( fLibHandle, ‘lua_rawgeti‘ );  
    626.   lua_createtable    := GetProcAddr( fLibHandle, ‘lua_createtable‘ );  
    627.   lua_newuserdata    := GetProcAddr( fLibHandle, ‘lua_newuserdata‘ );  
    628.   lua_getmetatable   := GetProcAddr( fLibHandle, ‘lua_getmetatable‘ );  
    629.   lua_getfenv        := GetProcAddr( fLibHandle, ‘lua_getfenv‘ );  
    630.   lua_settable       := GetProcAddr( fLibHandle, ‘lua_settable‘ );  
    631.   lua_setfield       := GetProcAddr( fLibHandle, ‘lua_setfield‘ );  
    632.   lua_rawset         := GetProcAddr( fLibHandle, ‘lua_rawset‘ );  
    633.   lua_rawseti        := GetProcAddr( fLibHandle, ‘lua_rawseti‘ );  
    634.   lua_setmetatable   := GetProcAddr( fLibHandle, ‘lua_setmetatable‘ );  
    635.   lua_setfenv        := GetProcAddr( fLibHandle, ‘lua_setfenv‘ );  
    636.   lua_call           := GetProcAddr( fLibHandle, ‘lua_call‘ );  
    637.   lua_pcall          := GetProcAddr( fLibHandle, ‘lua_pcall‘ );  
    638.   lua_cpcall         := GetProcAddr( fLibHandle, ‘lua_cpcall‘ );  
    639.   lua_load           := GetProcAddr( fLibHandle, ‘lua_load‘ );  
    640.   lua_dump           := GetProcAddr( fLibHandle, ‘lua_dump‘ );  
    641.   lua_yield          := GetProcAddr( fLibHandle, ‘lua_yield‘ );  
    642.   lua_resume         := GetProcAddr( fLibHandle, ‘lua_resume‘ );  
    643.   lua_status         := GetProcAddr( fLibHandle, ‘lua_status‘ );  
    644.   lua_gc             := GetProcAddr( fLibHandle, ‘lua_gc‘ );  
    645.   lua_error          := GetProcAddr( fLibHandle, ‘lua_error‘ );  
    646.   lua_next           := GetProcAddr( fLibHandle, ‘lua_next‘ );  
    647.   lua_concat         := GetProcAddr( fLibHandle, ‘lua_concat‘ );  
    648.   lua_getallocf      := GetProcAddr( fLibHandle, ‘lua_getallocf‘ );  
    649.   lua_setallocf      := GetProcAddr( fLibHandle, ‘lua_setallocf‘ );  
    650.   lua_getstack       := GetProcAddr( fLibHandle, ‘lua_getstack‘ );  
    651.   lua_getinfo        := GetProcAddr( fLibHandle, ‘lua_getinfo‘ );  
    652.   lua_getlocal       := GetProcAddr( fLibHandle, ‘lua_getlocal‘ );  
    653.   lua_setlocal       := GetProcAddr( fLibHandle, ‘lua_setlocal‘ );  
    654.   lua_getupvalue     := GetProcAddr( fLibHandle, ‘lua_getupvalue‘ );  
    655.   lua_setupvalue     := GetProcAddr( fLibHandle, ‘lua_setupvalue‘ );  
    656.   lua_sethook        := GetProcAddr( fLibHandle, ‘lua_sethook‘ );  
    657.   lua_gethook        := GetProcAddr( fLibHandle, ‘lua_gethook‘ );  
    658.   lua_gethookmask    := GetProcAddr( fLibHandle, ‘lua_gethookmask‘ );  
    659.   lua_gethookcount   := GetProcAddr( fLibHandle, ‘lua_gethookcount‘ );  
    660.   luaopen_base       := GetProcAddr( fLibHandle, ‘luaopen_base‘ );  
    661.   luaopen_table      := GetProcAddr( fLibHandle, ‘luaopen_table‘ );  
    662.   luaopen_io         := GetProcAddr( fLibHandle, ‘luaopen_io‘ );  
    663.   luaopen_os         := GetProcAddr( fLibHandle, ‘luaopen_os‘ );  
    664.   luaopen_string     := GetProcAddr( fLibHandle, ‘luaopen_string‘ );  
    665.   luaopen_math       := GetProcAddr( fLibHandle, ‘luaopen_math‘ );  
    666.   luaopen_debug      := GetProcAddr( fLibHandle, ‘luaopen_debug‘ );  
    667.   luaopen_package    := GetProcAddr( fLibHandle, ‘luaopen_package‘ );  
    668.   luaL_openlibs      := GetProcAddr( fLibHandle, ‘luaL_openlibs‘ );  
    669.   luaL_register      := GetProcAddr( fLibHandle, ‘luaL_register‘ );  
    670.   luaL_getmetafield  := GetProcAddr( fLibHandle, ‘luaL_getmetafield‘ );  
    671.   luaL_callmeta      := GetProcAddr( fLibHandle, ‘luaL_callmeta‘ );  
    672.   luaL_typerror      := GetProcAddr( fLibHandle, ‘luaL_typerror‘ );  
    673.   luaL_argerror      := GetProcAddr( fLibHandle, ‘luaL_argerror‘ );  
    674.   luaL_checklstring  := GetProcAddr( fLibHandle, ‘luaL_checklstring‘ );  
    675.   luaL_optlstring    := GetProcAddr( fLibHandle, ‘luaL_optlstring‘ );  
    676.   luaL_checknumber   := GetProcAddr( fLibHandle, ‘luaL_checknumber‘ );  
    677.   luaL_optnumber     := GetProcAddr( fLibHandle, ‘luaL_optnumber‘ );  
    678.   luaL_checkinteger  := GetProcAddr( fLibHandle, ‘luaL_checkinteger‘ );  
    679.   luaL_optinteger    := GetProcAddr( fLibHandle, ‘luaL_optinteger‘ );  
    680.   luaL_checkstack    := GetProcAddr( fLibHandle, ‘luaL_checkstack‘ );  
    681.   luaL_checktype     := GetProcAddr( fLibHandle, ‘luaL_checktype‘ );  
    682.   luaL_checkany      := GetProcAddr( fLibHandle, ‘luaL_checkany‘ );  
    683.   luaL_newmetatable  := GetProcAddr( fLibHandle, ‘luaL_newmetatable‘ );  
    684.   luaL_checkudata    := GetProcAddr( fLibHandle, ‘luaL_checkudata‘ );  
    685.   luaL_where         := GetProcAddr( fLibHandle, ‘luaL_where‘ );  
    686.   luaL_error         := GetProcAddr( fLibHandle, ‘luaL_error‘ );  
    687.   luaL_checkoption   := GetProcAddr( fLibHandle, ‘luaL_checkoption‘ );  
    688.   luaL_ref           := GetProcAddr( fLibHandle, ‘luaL_ref‘ );  
    689.   luaL_unref         := GetProcAddr( fLibHandle, ‘luaL_unref‘ );  
    690. {$ifdef LUA_COMPAT_GETN}  
    691.   luaL_getn          := GetProcAddr( fLibHandle, ‘luaL_getn‘ );  
    692.   luaL_setn          := GetProcAddr( fLibHandle, ‘luaL_setn‘ );  
    693. {$endif}  
    694.   luaL_loadfile      := GetProcAddr( fLibHandle, ‘luaL_loadfile‘ );  
    695.   luaL_loadbuffer    := GetProcAddr( fLibHandle, ‘luaL_loadbuffer‘ );  
    696.   luaL_loadstring    := GetProcAddr( fLibHandle, ‘luaL_loadstring‘ );  
    697.   luaL_newstate      := GetProcAddr( fLibHandle, ‘luaL_newstate‘ );  
    698.   luaL_gsub          := GetProcAddr( fLibHandle, ‘luaL_gsub‘ );  
    699.   luaL_findtable     := GetProcAddr( fLibHandle, ‘luaL_findtable‘ );  
    700.   luaL_buffinit      := GetProcAddr( fLibHandle, ‘luaL_buffinit‘ );  
    701.   luaL_prepbuffer    := GetProcAddr( fLibHandle, ‘luaL_prepbuffer‘ );  
    702.   luaL_addlstring    := GetProcAddr( fLibHandle, ‘luaL_addlstring‘ );  
    703.   luaL_addstring     := GetProcAddr( fLibHandle, ‘luaL_addstring‘ );  
    704.   luaL_addvalue      := GetProcAddr( fLibHandle, ‘luaL_addvalue‘ );  
    705.   luaL_pushresult    := GetProcAddr( fLibHandle, ‘luaL_pushresult‘ );  
    706.   
    707.   Result := fLibHandle;  
    708. end;  
    709.   
    710. procedure FreeLuaLib();  
    711. begin  
    712.   lua_newstate       := nil;  
    713.   lua_close          := nil;  
    714.   lua_newthread      := nil;  
    715.   lua_atpanic        := nil;  
    716.   lua_gettop         := nil;  
    717.   lua_settop         := nil;  
    718.   lua_pushvalue      := nil;  
    719.   lua_remove         := nil;  
    720.   lua_insert         := nil;  
    721.   lua_replace        := nil;  
    722.   lua_checkstack     := nil;  
    723.   lua_xmove          := nil;  
    724.   lua_isnumber       := nil;  
    725.   lua_isstring       := nil;  
    726.   lua_iscfunction    := nil;  
    727.   lua_isuserdata     := nil;  
    728.   lua_type           := nil;  
    729.   lua_typename       := nil;  
    730.   lua_equal          := nil;  
    731.   lua_rawequal       := nil;  
    732.   lua_lessthan       := nil;  
    733.   lua_tonumber       := nil;  
    734.   lua_tointeger      := nil;  
    735.   lua_toboolean      := nil;  
    736.   lua_tolstring      := nil;  
    737.   lua_objlen         := nil;  
    738.   lua_tocfunction    := nil;  
    739.   lua_touserdata     := nil;  
    740.   lua_tothread       := nil;  
    741.   lua_topointer      := nil;  
    742.   lua_pushnil        := nil;  
    743.   lua_pushnumber     := nil;  
    744.   lua_pushinteger    := nil;  
    745.   lua_pushlstring    := nil;  
    746.   lua_pushstring     := nil;  
    747.   lua_pushvfstring   := nil;  
    748.   lua_pushfstring    := nil;  
    749.   lua_pushcclosure   := nil;  
    750.   lua_pushboolean    := nil;  
    751.   lua_pushlightuserdata := nil;  
    752.   lua_pushthread     := nil;  
    753.   lua_gettable       := nil;  
    754.   lua_getfield       := nil;  
    755.   lua_rawget         := nil;  
    756.   lua_rawgeti        := nil;  
    757.   lua_createtable    := nil;  
    758.   lua_newuserdata    := nil;  
    759.   lua_getmetatable   := nil;  
    760.   lua_getfenv        := nil;  
    761.   lua_settable       := nil;  
    762.   lua_setfield       := nil;  
    763.   lua_rawset         := nil;  
    764.   lua_rawseti        := nil;  
    765.   lua_setmetatable   := nil;  
    766.   lua_setfenv        := nil;  
    767.   lua_call           := nil;  
    768.   lua_pcall          := nil;  
    769.   lua_cpcall         := nil;  
    770.   lua_load           := nil;  
    771.   lua_dump           := nil;  
    772.   lua_yield          := nil;  
    773.   lua_resume         := nil;  
    774.   lua_status         := nil;  
    775.   lua_gc             := nil;  
    776.   lua_error          := nil;  
    777.   lua_next           := nil;  
    778.   lua_concat         := nil;  
    779.   lua_getallocf      := nil;  
    780.   lua_setallocf      := nil;  
    781.   lua_getstack       := nil;  
    782.   lua_getinfo        := nil;  
    783.   lua_getlocal       := nil;  
    784.   lua_setlocal       := nil;  
    785.   lua_getupvalue     := nil;  
    786.   lua_setupvalue     := nil;  
    787.   lua_sethook        := nil;  
    788.   lua_gethook        := nil;  
    789.   lua_gethookmask    := nil;  
    790.   lua_gethookcount   := nil;  
    791.   luaopen_base       := nil;  
    792.   luaopen_table      := nil;  
    793.   luaopen_io         := nil;  
    794.   luaopen_os         := nil;  
    795.   luaopen_string     := nil;  
    796.   luaopen_math       := nil;  
    797.   luaopen_debug      := nil;  
    798.   luaopen_package    := nil;  
    799.   luaL_openlibs      := nil;  
    800.   luaL_register      := nil;  
    801.   luaL_getmetafield  := nil;  
    802.   luaL_callmeta      := nil;  
    803.   luaL_typerror      := nil;  
    804.   luaL_argerror      := nil;  
    805.   luaL_checklstring  := nil;  
    806.   luaL_optlstring    := nil;  
    807.   luaL_checknumber   := nil;  
    808.   luaL_optnumber     := nil;  
    809.   luaL_checkinteger  := nil;  
    810.   luaL_optinteger    := nil;  
    811.   luaL_checkstack    := nil;  
    812.   luaL_checktype     := nil;  
    813.   luaL_checkany      := nil;  
    814.   luaL_newmetatable  := nil;  
    815.   luaL_checkudata    := nil;  
    816.   luaL_where         := nil;  
    817.   luaL_error         := nil;  
    818.   luaL_checkoption   := nil;  
    819.   luaL_ref           := nil;  
    820.   luaL_unref         := nil;  
    821. {$ifdef LUA_COMPAT_GETN}  
    822.   luaL_getn          := nil;  
    823.   luaL_setn          := nil;  
    824. {$endif}  
    825.   luaL_loadfile      := nil;  
    826.   luaL_loadbuffer    := nil;  
    827.   luaL_loadstring    := nil;  
    828.   luaL_newstate      := nil;  
    829.   luaL_gsub          := nil;  
    830.   luaL_findtable     := nil;  
    831.   luaL_buffinit      := nil;  
    832.   luaL_prepbuffer    := nil;  
    833.   luaL_addlstring    := nil;  
    834.   luaL_addstring     := nil;  
    835.   luaL_addvalue      := nil;  
    836.   luaL_pushresult    := nil;  
    837.   
    838.   if fLibHandle <> 0 then begin  
    839.      FreeLibrary( fLibHandle );  
    840.      fLibHandle := 0;  
    841.   end;  
    842. end;  
    843.   
    844. {$ifndef LUA_COMPAT_GETN}  
    845. function luaL_getn(L: lua_State; t: Integer): Integer;  
    846. begin  
    847.   Result := lua_objlen(L, t);  
    848. end;  
    849.   
    850. procedure luaL_setn(L: lua_State; t, n: Integer);  
    851. begin  
    852. end;  
    853. {$endif}  
    854.   
    855. function lua_upvalueindex(i: Integer): Integer;  
    856. begin  
    857.   Result := LUA_GLOBALSINDEX - i;  
    858. end;  
    859.   
    860. procedure lua_pop(L: lua_State; n: Integer);  
    861. begin  
    862.   lua_settop(L, -(n) - 1);  
    863. end;  
    864.   
    865. procedure lua_newtable(L: lua_State);  
    866. begin  
    867.   lua_createtable(L, 0, 0);  
    868. end;  
    869.   
    870. function lua_strlen(L: lua_State; i: Integer): Cardinal;  
    871. begin  
    872.   result := lua_objlen(L, i);  
    873. end;  
    874.   
    875. procedure lua_register(L: lua_state; name: PAnsiChar; f: lua_CFunction);  
    876. begin  
    877.   lua_pushcfunction(L, f);  
    878.   lua_setglobal(L, name);  
    879. end;  
    880.   
    881. procedure lua_pushcfunction(L: lua_State; f: lua_CFunction);  
    882. begin  
    883.   lua_pushcclosure(L, f, 0);  
    884. end;  
    885.   
    886. function lua_isfunction(L: lua_State; idx: Integer): Boolean;  
    887. begin  
    888.   Result := lua_type(L, idx) = LUA_TFUNCTION;  
    889. end;  
    890.   
    891. function lua_istable(L: lua_State; idx: Integer): Boolean;  
    892. begin  
    893.   Result := lua_type(L, idx) = LUA_TTABLE;  
    894. end;  
    895.   
    896. function lua_islightuserdata(L: lua_State; idx: Integer): Boolean;  
    897. begin  
    898.   Result := lua_type(L, idx) = LUA_TLIGHTUSERDATA;  
    899. end;  
    900.   
    901. function lua_isnil(L: lua_State; idx: Integer): Boolean;  
    902. begin  
    903.   Result := lua_type(L, idx) = LUA_TNIL;  
    904. end;  
    905.   
    906. function lua_isboolean(L: lua_State; idx: Integer): Boolean;  
    907. begin  
    908.   Result := lua_type(L, idx) = LUA_TBOOLEAN;  
    909. end;  
    910.   
    911. function lua_isthread(L: lua_State; idx: Integer): Boolean;  
    912. begin  
    913.   Result := lua_type(L, idx) = LUA_TTHREAD;  
    914. end;  
    915.   
    916. function lua_isnone(L: lua_State; idx: Integer): Boolean;  
    917. begin  
    918.   Result := lua_type(L, idx) = LUA_TNONE;  
    919. end;  
    920.   
    921. function lua_isnoneornil(L: lua_State; idx: Integer): Boolean;  
    922. begin  
    923.   Result := lua_type(L, idx) <= 0;  
    924. end;  
    925.   
    926. procedure lua_pushliteral(L: lua_State; s: PAnsiChar);  
    927. begin  
    928.   lua_pushlstring(L, s, StrLen(s));  
    929. end;  
    930.   
    931. procedure lua_setglobal(L: lua_State; name: PAnsiChar);  
    932. begin  
    933.   lua_setfield(L, LUA_GLOBALSINDEX, name);  
    934. end;  
    935.   
    936. procedure lua_getglobal(L: lua_State; name: PAnsiChar);  
    937. begin  
    938.   lua_getfield(L, LUA_GLOBALSINDEX, name);  
    939. end;  
    940.   
    941. function lua_tostring(L: lua_State; idx: Integer): PAnsiChar;  
    942. var  
    943.   len: Cardinal;  
    944. begin  
    945.   Result := lua_tolstring(L, idx, len);  
    946. end;  
    947.   
    948. function lua_getgccount(L: lua_State): Integer;  
    949. begin  
    950.   Result := lua_gc(L, LUA_GCCOUNT, 0);  
    951. end;  
    952.   
    953. function lua_open(): lua_State;  
    954. begin  
    955.   Result := luaL_newstate();  
    956. end;  
    957.   
    958. procedure lua_getregistry(L: lua_State);  
    959. begin  
    960.   lua_pushvalue(L, LUA_REGISTRYINDEX);  
    961. end;  
    962.   
    963. function lua_ref(L: lua_State; lock: Boolean): Integer;  
    964. begin  
    965.   if lock then  
    966.      Result := luaL_ref(L, LUA_REGISTRYINDEX)  
    967.   else begin  
    968.      lua_pushstring(L, ‘unlocked references are obsolete‘);  
    969.      Result := lua_error(L);  
    970.   end;  
    971. end;  
    972.   
    973. procedure lua_unref(L: lua_State; ref: Integer);  
    974. begin  
    975.   luaL_unref(L, LUA_REGISTRYINDEX, ref);  
    976. end;  
    977.   
    978. procedure lua_getref(L: lua_State; ref: Integer);  
    979. begin  
    980.   lua_rawgeti(L, LUA_REGISTRYINDEX, ref);  
    981. end;  
    982.   
    983. procedure lua_assert(c: Boolean);  
    984. begin  
    985. end;  
    986.   
    987. function lua_number2str(s: Lua_Number; n: Integer): String;  
    988. begin  
    989.   Result := FormatFloat( LUA_NUMBER_FMT, RoundTo( s, n ) );  
    990. end;  
    991.   
    992. function lua_str2number(s: String; p: integer): Lua_Number;  
    993. begin  
    994.   Result := RoundTo( StrToFloat( s ), p );  
    995. end;  
    996.   
    997. function luaL_argcheck(L: lua_State; cond: Boolean; narg: Integer; extramsg: PAnsiChar): Integer;  
    998. begin  
    999.   if cond then  
    1000.      Result := 0  
    1001.   else  
    1002.      Result := luaL_argerror(L, narg, extramsg);  
    1003. end;  
    1004.   
    1005. function luaL_checkstring(L: lua_State; narg: Integer): PAnsiChar;  
    1006. var  
    1007.   ls: Cardinal;  
    1008. begin  
    1009.   Result := luaL_checklstring(L, narg, ls);  
    1010. end;  
    1011.   
    1012. function luaL_optstring(L: lua_State; narg: Integer; d: PAnsiChar): PAnsiChar;  
    1013. var  
    1014.   ls: Cardinal;  
    1015. begin  
    1016.   Result := luaL_optlstring(L, narg, d, ls);  
    1017. end;  
    1018.   
    1019. function luaL_checkint(L: lua_State; narg: Integer): Integer;  
    1020. begin  
    1021.   Result := Trunc(luaL_checkinteger(L, narg));  
    1022. end;  
    1023.   
    1024. function luaL_optint(L: lua_State; narg, d: Integer): Integer;  
    1025. begin  
    1026.   Result := Trunc(luaL_optinteger(L, narg, d));  
    1027. end;  
    1028.   
    1029. function luaL_checklong(L: lua_State; narg: Integer): LongInt;  
    1030. begin  
    1031.   Result := Trunc(luaL_checkinteger(L, narg));  
    1032. end;  
    1033.   
    1034. function luaL_optlong(L: lua_State; narg: Integer; d: LongInt): LongInt;  
    1035. begin  
    1036.   Result := Trunc(luaL_optinteger(L, narg, d));  
    1037. end;  
    1038.   
    1039. function luaL_typename(L: lua_State; idx: Integer): PAnsiChar;  
    1040. begin  
    1041.   Result := lua_typename(L, lua_type(L, idx));  
    1042. end;  
    1043.   
    1044. function luaL_dofile(L: lua_State; filename: PAnsiChar): Integer;  
    1045. begin  
    1046.   Result := luaL_loadfile(L, filename);  
    1047.   
    1048.   If Result = 0 Then  
    1049.      Result := lua_pcall(L, 0, LUA_MULTRET, 0);  
    1050. end;  
    1051.   
    1052. function luaL_dostring(L: lua_State; str: PAnsiChar): Integer;  
    1053. begin  
    1054.   Result := luaL_loadstring(L, str);  
    1055.     
    1056.   If Result = 0 Then  
    1057.      Result := lua_pcall(L, 0, LUA_MULTRET, 0);  
    1058. end;  
    1059.   
    1060. procedure luaL_getmetatable(L: lua_State; tname: PAnsiChar);  
    1061. begin  
    1062.    lua_getfield(L, LUA_REGISTRYINDEX, tname);  
    1063. end;  
    1064.   
    1065. procedure luaL_addchar(var B: luaL_Buffer; c: AnsiChar);  
    1066. begin  
    1067.   if Integer(B.p) < Integer(B.buffer + LUAL_BUFFERSIZE) then  
    1068.      luaL_prepbuffer(B);  
    1069.   
    1070.   B.p^ := c;  
    1071.   Inc(B.p);  
    1072. {  // original C code 
    1073. #define luaL_addchar(B,c) \ 
    1074.   ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \ 
    1075.    (*(B)->p++ = (char)(c))) 
    1076. }  
    1077. end;  
    1078.   
    1079. procedure luaL_putchar(var B: luaL_Buffer; c: AnsiChar);  
    1080. begin  
    1081.   luaL_addchar(B, c);  
    1082. end;  
    1083.   
    1084. procedure luaL_addsize(var B: luaL_Buffer; n: Cardinal);  
    1085. begin  
    1086.   Inc(B.p, n);  
    1087. end;  
    1088.   
    1089. function luaL_check_lstr(L: lua_State; numArg: Integer; var ls: Cardinal): PAnsiChar;  
    1090. begin  
    1091.   Result := luaL_checklstring(L, numArg, ls);  
    1092. end;  
    1093.   
    1094. function luaL_opt_lstr(L: lua_State; numArg: Integer; def: PAnsiChar; var ls: Cardinal): PAnsiChar;  
    1095. begin  
    1096.   Result := luaL_optlstring(L, numArg, def, ls);  
    1097. end;  
    1098.   
    1099. function luaL_check_number(L: lua_State; numArg: Integer): lua_Number;  
    1100. begin  
    1101.   Result := luaL_checknumber(L, numArg);  
    1102. end;  
    1103.   
    1104. function luaL_opt_number(L: lua_State; nArg: Integer; def: lua_Number): lua_Number;  
    1105. begin  
    1106.   Result := luaL_optnumber(L, nArg, def);  
    1107. end;  
    1108.   
    1109. function luaL_arg_check(L: lua_State; cond: Boolean; numarg: Integer; extramsg: PAnsiChar): Integer;  
    1110. begin  
    1111.   Result := luaL_argcheck(L, cond, numarg, extramsg);  
    1112. end;  
    1113.   
    1114. function luaL_check_string(L: lua_State; n: Integer): PAnsiChar;  
    1115. begin  
    1116.   Result := luaL_checkstring(L, n);  
    1117. end;  
    1118.   
    1119. function luaL_opt_string(L: lua_State; n: Integer; d: PAnsiChar): PAnsiChar;  
    1120. begin  
    1121.   Result := luaL_optstring(L, n, d);  
    1122. end;  
    1123.   
    1124. function luaL_check_int(L: lua_State; n: Integer): Integer;  
    1125. begin  
    1126.   Result := luaL_checkint(L, n);  
    1127. end;  
    1128.   
    1129. function luaL_check_long(L: lua_State; n: LongInt): LongInt;  
    1130. begin  
    1131.   Result := luaL_checklong(L, n);  
    1132. end;  
    1133.   
    1134. function luaL_opt_int(L: lua_State; n, d: Integer): Integer;  
    1135. begin  
    1136.   Result := luaL_optint(L, n, d);  
    1137. end;  
    1138.   
    1139. function luaL_opt_long(L: lua_State; n: Integer; d: LongInt): LongInt;  
    1140. begin  
    1141.   Result := luaL_optlong(L, n, d);  
    1142. end;  
    1143.   
    1144. end.  

delphi调用LUA函数来处理一些逻辑

原文:http://www.cnblogs.com/yzryc/p/6401803.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!