• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

替同事做了个洛奇英雄传自动染色程序,关于屏幕取色的.因为里面他对颜色的要求比较复杂,改动也比较大,于是我让他把逻辑写在 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.  * @package     Delphi Lua 
  3.  * @copyright   Copyright (c) 2009 Dennis D. Spreen (http://www.spreendigital.de/blog) 
  4.  * @license     http://opensource.org/licenses/gpl-license.php GNU Public License 
  5.  * @author      Dennis D. Spreen <[email protected]
  6.  * @version     1.3 
  7.  * @revision    $Id: Lua.pas 102 2009-09-30 11:39:41Z dennis.spreen $ 
  8.  */ 
  9.  
  10. History 
  11. 1.3     DS      Improved Callback, now uses pointer instead of object index 
  12.                 Modified RegisterFunctions to allow methods from other class 
  13.                 to be registered, moved object table into TLua class 
  14. 1.2 DS  Added example on how to extend lua with a delphi dll 
  15. 1.1     DS      Improved global object table, this optimizes the delphi 
  16.                 function calls 
  17. 1.0     DS      Initial Release 
  18.  
  19. Copyright 2009  Dennis D. Spreen (email : [email protected]
  20.  
  21. This program is free software; you can redistribute it and/or modify 
  22. it under the terms of the GNU General Public License as published by 
  23. the Free Software Foundation; either version 2 of the License, or 
  24. (at your option) any later version. 
  25.  
  26. This program is distributed in the hope that it will be useful, 
  27. but WITHOUT ANY WARRANTY; without even the implied warranty of 
  28. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  29. GNU General Public License for more details. 
  30.  
  31. You should have received a copy of the GNU General Public License 
  32. along with this program; if not, write to the Free Software 
  33. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
  34. }  
  35.   
  36. unit Lua;  
  37.   
  38. interface  
  39.   
  40. uses  
  41.   Classes,  
  42.   LuaLib;  
  43.   
  44. type  
  45.   TLuaState = Lua_State;  
  46.   
  47.   TLua = class(TObject)  
  48.   private  
  49.     fAutoRegister: Boolean;  
  50.     CallbackList: TList;  // internal callback list  
  51.   public  
  52.     LuaInstance: TLuaState;  // Lua instance  
  53.     constructor Create(AutoRegister: Boolean = True); overload; virtual;  
  54.     destructor Destroy; override;  
  55.     function DoFile(Filename: String): Integer; virtual;// load file and execute  
  56.     procedure RegisterFunction(FuncName: AnsiString; MethodName: AnsiString = ''; Obj: TObject = NIL); virtual; //register function  
  57.     procedure AutoRegisterFunctions(Obj: TObject);  // register all published functions  
  58.     procedure UnregisterFunctions(Obj: TObject); // unregister all object functions  
  59.   end;  
  60.   
  61. implementation  
  62.   
  63. type  
  64.   TProc = function(L: TLuaState): Integer of object; // Lua Function  
  65.   
  66.   TCallback = class  
  67.     Routine: TMethod;  // Code and Data for the method  
  68.     Exec: TProc;       // Resulting execution function  
  69.   end;  
  70.   
  71. //  
  72. // This function is called by Lua, it extracts the object by  
  73. // pointer to the objects method by name, which is then called.  
  74. //  
  75. // @param       Lua_State   L   Pointer to Lua instance  
  76. // @return      Integer         Number of result arguments on stack  
  77. //  
  78. function LuaCallBack(L: Lua_State): Integer; cdecl;  
  79. var  
  80.   CallBack: TCallBack;       // The Object stored in the Object Table  
  81. begin  
  82.   // Retrieve first Closure Value (=Object Pointer)  
  83.   CallBack := lua_topointer(L, lua_upvalueindex(1));  
  84.   
  85.   // Execute only if Object is valid  
  86.   if (assigned(CallBack) and assigned(CallBack.Exec)) then  
  87.     Result := CallBack.Exec(L)  
  88.   else  
  89.     Result := 0;  
  90. end;  
  91.   
  92. { TLua }  
  93.   
  94. //  
  95. // Create a new Lua instance and optionally create Lua functions  
  96. //  
  97. // @param       Boolean      AutoRegister       (optional)  
  98. // @return      TLua                            Lua Instance  
  99. //  
  100. constructor TLua.Create(AutoRegister: Boolean = True);  
  101. begin  
  102.   inherited Create;  
  103.   // Load Lua Lib if not already done  
  104.   if (not LuaLibLoaded) then  
  105.     LoadLuaLib;  
  106.   
  107.   // Open Library  
  108.   LuaInstance := Lua_Open();  
  109.   luaopen_base(LuaInstance);  
  110.   
  111.   fAutoRegister := AutoRegister;  
  112.   
  113.   // Create Object List on initialization  
  114.   CallBackList := TList.Create;  
  115.   
  116.   // if set then register published functions  
  117.   if (AutoRegister) then  
  118.     AutoRegisterFunctions(self);  
  119. end;  
  120.   
  121. //  
  122. // Dispose Lua instance  
  123. //  
  124. destructor TLua.Destroy;  
  125. begin  
  126.   // Unregister all functions if previously autoregistered  
  127.   if (fAutoRegister) then  
  128.     UnregisterFunctions(Self);  
  129.   
  130.   // dispose Object List on finalization  
  131.   CallBackList.Free;  
  132.   
  133.   // Close instance  
  134.   Lua_Close(LuaInstance);  
  135.   inherited;  
  136. end;  
  137.   
  138. //  
  139. // Wrapper for Lua File load and Execution  
  140. //  
  141. // @param       String  Filename        Lua Script file name  
  142. // @return      Integer  
  143. //  
  144. function TLua.DoFile(Filename: String): Integer;  
  145. begin  
  146.   Result := lual_dofile(LuaInstance, PAnsiChar(AnsiString(Filename)));  
  147. end;  
  148.   
  149. //  
  150. // Register a new Lua Function and map it to the Objects method name  
  151. //  
  152. // @param       AnsiString      FuncName        Lua Function Name  
  153. // @param       AnsiString      MethodName      (optional) Objects Method name  
  154. //  
  155. procedure TLua.RegisterFunction(FuncName: AnsiString; MethodName: AnsiString = ''; Obj: TObject = NIL);  
  156. var  
  157.   CallBack: TCallBack; // Callback Object  
  158. begin  
  159.   // if method name not specified use Lua function name  
  160.   if (MethodName = '') then  
  161.     MethodName := FuncName;  
  162.   
  163.   // if not object specified use this object  
  164.   if (Obj = NIL) then  
  165.     Obj := Self;  
  166.   
  167.   // Add Callback Object to the Object Index  
  168.   CallBack := TCallBack.Create;  
  169.   CallBack.Routine.Data := Obj;  
  170.   CallBack.Routine.Code := Obj.MethodAddress(String(MethodName));  
  171.   CallBack.Exec := TProc(CallBack.Routine);  
  172.   CallbackList.Add(CallBack);  
  173.   
  174.   // prepare Closure value (Method Name)  
  175.   lua_pushstring(LuaInstance, PAnsiChar(FuncName));  
  176.   
  177.   // prepare Closure value (CallBack Object Pointer)  
  178.   lua_pushlightuserdata(LuaInstance, CallBack);  
  179.   
  180.   // set new Lua function with Closure value  
  181.   lua_pushcclosure(LuaInstance, LuaCallBack, 1);  
  182.   lua_settable(LuaInstance, LUA_GLOBALSINDEX);  
  183. end;  
  184.   
  185. //  
  186. // UnRegister all new Lua Function  
  187. //  
  188. // @param       TObject     Object      Object with prev registered lua functions  
  189. //  
  190. procedure TLua.UnregisterFunctions(Obj: TObject);  
  191. var  
  192.   I: Integer;  
  193.   CallBack: TCallBack;  
  194. begin  
  195.   // remove obj from object list  
  196.   for I := CallBackList.Count downto do  
  197.   begin  
  198.     CallBack := CallBackList[I-1];  
  199.     if (assigned(CallBack)) and (CallBack.Routine.Data = Obj) then  
  200.     begin  
  201.       CallBack.Free;  
  202.       CallBackList.Items[I-1] := NIL;  
  203.       CallBackList.Delete(I-1);  
  204.     end;  
  205.   end;  
  206. end;  
  207.   
  208. //  
  209. // Register all published methods as Lua Functions  
  210. //  
  211. procedure TLua.AutoRegisterFunctions(Obj: TObject);  
  212. type  
  213.   PPointer = ^Pointer;  
  214.   PMethodRec = ^TMethodRec;  
  215.   
  216.   TMethodRec = packed record  
  217.     wSize: Word;  
  218.     pCode: Pointer;  
  219.     sName: ShortString;  
  220.   end;  
  221. var  
  222.   MethodTable: PAnsiChar;  
  223.   MethodRec: PMethodRec;  
  224.   wCount: Word;  
  225.   nMethod: Integer;  
  226. begin  
  227.   // Get a pointer to the class's published method table  
  228.   MethodTable := PAnsiChar(Pointer(PAnsiChar(Obj.ClassType) + vmtMethodTable)^);  
  229.   
  230.   if (MethodTable <> Nil) then  
  231.   begin  
  232.     // Get the count of the methods in the table  
  233.     Move(MethodTable^, wCount, 2);  
  234.   
  235.     // Position the MethodRec pointer at the first method in the table  
  236.     // (skip over the 2-byte method count)  
  237.     MethodRec := PMethodRec(MethodTable + 2);  
  238.   
  239.     // Iterate through all the published methods of this class  
  240.     for nMethod := to wCount - do  
  241.     begin  
  242.       // Add the method name to the lua functions  
  243.       RegisterFunction(MethodRec.sName, MethodRec.sName, Obj);  
  244.       // Skip to the next method  
  245.       MethodRec := PMethodRec(PAnsiChar(MethodRec) + MethodRec.wSize);  
  246.     end;  
  247.   end;  
  248. end;  
  249.   
  250.   
  251. 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. * Copyright for the Delphi adaptation: 
  6. *  2005 Rolf Meyerhoff 
  7. *  www.matrix44.de 
  8. * Copyright for the Lua 5.1 adaptation: 
  9. *  2007 Marco Antonio Abreu 
  10. *  www.marcoabreu.eti.br 
  11. *  All rights reserved. 
  12. * Permission is hereby granted, free of charge, to any person obtaining 
  13. * a copy of this software and associated documentation files (the 
  14. * "Software"), to deal in the Software without restriction, including 
  15. * without limitation the rights to use, copy, modify, merge, publish, 
  16. * distribute, sublicense, and/or sell copies of the Software, and to 
  17. * permit persons to whom the Software is furnished to do so, subject to 
  18. * the following conditions: 
  19. * The above copyright notice and this permission notice shall be 
  20. * included in all copies or substantial portions of the Software. 
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
  22. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
  23. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
  24. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 
  25. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
  26. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
  27. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
  28. ******************************************************************************)  
  29. unit LuaLib;  
  30.   
  31. interface  
  32.   
  33. const  
  34.   LUA_VERSION   = 'Lua 5.1';  
  35.   LUA_RELEASE   = 'Lua 5.1.2';  
  36.   LUA_COPYRIGHT = 'Copyright (C) 1994-2004 Tecgraf, PUC-Rio';  
  37.   LUA_AUTHORS   = 'R. Ierusalimschy, L. H. de Figueiredo & W. Celes';  
  38.   
  39.   LUA_PASCAL_51_AUTHOR = 'Marco Antonio Abreu';  
  40.   LUA_PASCAL_51_COPYRIGHT = 'Copyright (C) 2007 Marco Antonio Abreu';  
  41.   
  42.   (* mark for precompiled code (`<esc>Lua') *)  
  43.   LUA_SIGNATURE = #27'Lua';  
  44.   
  45.   (* option for multiple returns in `lua_pcall' and `lua_call' *)  
  46.   LUA_MULTRET   = -1;  
  47.   
  48.   (* 
  49.   ** pseudo-indices 
  50.   *)  
  51.   LUA_REGISTRYINDEX = -10000;  
  52.   LUA_ENVIRONINDEX  = -10001;  
  53.   LUA_GLOBALSINDEX  = -10002;  
  54.   
  55.   (* thread status; 0 is OK *)  
  56.   LUA_TRD_YIELD = 1;  
  57.   LUA_ERRRUN    = 2;  
  58.   LUA_ERRSYNTAX = 3;  
  59.   LUA_ERRMEM    = 4;  
  60.   LUA_ERRERR    = 5;  
  61.   
  62.   (* extra error code for `luaL_load' *)  
  63.   LUA_ERRFILE   = LUA_ERRERR + 1;  
  64.   
  65.   (* 
  66.   ** basic types 
  67.   *)  
  68.   LUA_TNONE          = -1;  
  69.   LUA_TNIL           = 0;  
  70.   LUA_TBOOLEAN       = 1;  
  71.   LUA_TLIGHTUSERDATA = 2;  
  72.   LUA_TNUMBER        = 3;  
  73.   LUA_TSTRING        = 4;  
  74.   LUA_TTABLE         = 5;  
  75.   LUA_TFUNCTION      = 6;  
  76.   LUA_TUSERDATA      = 7;  
  77.   LUA_TTHREAD        = 8;  
  78.   
  79.   (* minimum Lua stack available to a C function *)  
  80.   LUA_MINSTACK       = 20;  
  81.   
  82.   (* 
  83.   ** garbage-collection function and options 
  84.   *)  
  85.   LUA_GCSTOP        = 0;  
  86.   LUA_GCRESTART     = 1;  
  87.   LUA_GCCOLLECT     = 2;  
  88.   LUA_GCCOUNT       = 3;  
  89.   LUA_GCCOUNTB      = 4;  
  90.   LUA_GCSTEP        = 5;  
  91.   LUA_GCSETPAUSE    = 6;  
  92.   LUA_GCSETSTEPMUL  = 7;  
  93.   
  94.   (* 
  95.   ** {====================================================================== 
  96.   ** Debug API 
  97.   ** ======================================================================= 
  98.   *)  
  99.   
  100.   (* 
  101.   ** Event codes 
  102.   *)  
  103.   LUA_HOOKCALL    = 0;  
  104.   LUA_HOOKRET     = 1;  
  105.   LUA_HOOKLINE    = 2;  
  106.   LUA_HOOKCOUNT   = 3;  
  107.   LUA_HOOKTAILRET = 4;  
  108.   
  109.   (* 
  110.   ** Event masks 
  111.   *)  
  112.   LUA_MASKCALL  = (shl LUA_HOOKCALL);  
  113.   LUA_MASKRET   = (shl LUA_HOOKRET);  
  114.   LUA_MASKLINE  = (shl LUA_HOOKLINE);  
  115.   LUA_MASKCOUNT = (shl LUA_HOOKCOUNT);  
  116.   
  117.   (* 
  118.   ** {====================================================================== 
  119.   ** useful definitions for Lua kernel and libraries 
  120.   ** ======================================================================= 
  121.   *)  
  122.   
  123.   (* 
  124.   @@ LUA_NUMBER_SCAN is the format for reading numbers. 
  125.   @@ LUA_NUMBER_FMT is the format for writing numbers. 
  126.   @@ lua_number2str converts a number to a string. 
  127.   @@ LUAI_MAXNUMBER2STR is maximum size of previous conversion. 
  128.   @@ lua_str2number converts a string to a number. 
  129.   *)  
  130.   LUA_NUMBER_SCAN   =   '%lf';  
  131.   LUA_NUMBER_FMT     =  '%.14g';  
  132.   LUAI_MAXNUMBER2STR =  32;  (* 16 digits, sign, point, and \0 *)  
  133.   
  134.   (* pre-defined references *)  
  135.   LUA_NOREF  = -2;  
  136.   LUA_REFNIL = -1;  
  137.   
  138.   LUA_IDSIZE = 60;  
  139.   
  140.   (* 
  141.   ** package names 
  142.   *)  
  143.   LUA_COLIBNAME   = 'coroutine';  
  144.   LUA_TABLIBNAME  = 'table';  
  145.   LUA_IOLIBNAME   = 'io';  
  146.   LUA_OSLIBNAME   = 'os';  
  147.   LUA_STRLIBNAME  = 'string';  
  148.   LUA_MATHLIBNAME = 'math';  
  149.   LUA_DBLIBNAME   = 'debug';  
  150.   LUA_LOADLIBNAME = 'package';  
  151.   
  152.   (* 
  153.   ** {====================================================== 
  154.   ** Generic Buffer manipulation 
  155.   ** ======================================================= 
  156.   *)  
  157.   
  158.   BUFSIZ = 512; (* From stdio.h *)  
  159.   LUAL_BUFFERSIZE = BUFSIZ;  
  160.   
  161. type  
  162.   lua_State = type Pointer;  
  163.   
  164.   lua_CFunction = function(L: lua_State): Integer; cdecl;  
  165.   
  166.   (* 
  167.   ** functions that read/write blocks when loading/dumping Lua chunks 
  168.   *)  
  169.   lua_Reader = function(L: lua_State; data: Pointer; var size: Cardinal): PAnsiChar; cdecl;  
  170.   lua_Writer = function(L: lua_State; p: Pointer; sz: Cardinal; ud: Pointer): Integer; cdecl;  
  171.   
  172.   (* 
  173.   ** prototype for memory-allocation functions 
  174.   *)  
  175.   lua_Alloc = function(ud, ptr: Pointer; osize, nsize: Cardinal): Pointer; cdecl;  
  176.   
  177.   (* type of numbers in Lua *)  
  178.   lua_Number  = type double;  
  179.   (* type for integer functions *)  
  180.   lua_Integer = type integer;  
  181.   
  182.   lua_Debug = packed record  
  183.     event: Integer;  
  184.     name: PAnsiChar; (* (n) *)  
  185.     namewhat: PAnsiChar; (* (n) `global', `local', `field', `method' *)  
  186.     what: PAnsiChar; (* (S) `Lua', `C', `main', `tail' *)  
  187.     source: PAnsiChar; (* (S) *)  
  188.     currentline: Integer; (* (l) *)  
  189.     nups: Integer;  (* (u) number of upvalues *)  
  190.     linedefined: Integer; (* (S) *)  
  191.     lastlinedefine: Integer;    (* (S) *)  
  192.     short_src: array[0..LUA_IDSIZE - 1] of AnsiChar; (* (S) *)  
  193.     (* private part *)  
  194.     i_ci: Integer; (* active function *)  
  195.   end;  
  196.   
  197.   (* Functions to be called by the debuger in specific events *)  
  198.   lua_Hook = procedure(L: lua_State; var ar: lua_Debug); cdecl;  
  199.   
  200.   (* Lua Record *)  
  201.   PluaL_reg = ^luaL_reg;  
  202.   luaL_reg = packed record  
  203.     name: PAnsiChar;  
  204.     func: lua_CFunction;  
  205.   end;  
  206.   
  207.   (* 
  208.   ** {====================================================== 
  209.   ** Generic Buffer manipulation 
  210.   ** ======================================================= 
  211.   *)  
  212.   
  213.   luaL_Buffer = packed record  
  214.     p: PAnsiChar; (* current position in buffer *)  
  215.     lvl: Integer;  (* number of strings in the stack (level) *)  
  216.     L: lua_State;  
  217.     buffer: array[0..LUAL_BUFFERSIZE - 1] of AnsiChar;  
  218.   end;  
  219.   
  220. var  
  221.   (* 
  222.   ** state manipulation 
  223.   *)  
  224.   lua_newstate:  function(f: lua_Alloc; ud: Pointer): lua_State; cdecl;  
  225.   lua_close:     procedure(L: lua_State); cdecl;  
  226.   lua_newthread: function(L: lua_State): lua_State; cdecl;  
  227.   lua_atpanic:   function(L: lua_State; panicf: lua_CFunction): lua_CFunction; cdecl;  
  228.   
  229.   (* 
  230.   ** basic stack manipulation 
  231.   *)  
  232.   lua_gettop:     function(L: lua_State): Integer; cdecl;  
  233.   lua_settop:     procedure(L: lua_State; idx: Integer); cdecl;  
  234.   lua_pushvalue:  procedure(L: lua_State; idx: Integer); cdecl;  
  235.   lua_remove:     procedure(L: lua_State; idx: Integer); cdecl;  
  236.   lua_insert:     procedure(L: lua_State; idx: Integer); cdecl;  
  237.   lua_replace:    procedure(L: lua_State; idx: Integer); cdecl;  
  238.   lua_checkstack: function(L: lua_State; extra: Integer): LongBool; cdecl;  
  239.   lua_xmove:      procedure(from, dest: lua_State; n: Integer); cdecl;  
  240.   
  241.   (* 
  242.   ** access functions (stack -> C/Pascal) 
  243.   *)  
  244.   
  245.   lua_isnumber:    function(L: lua_State; idx: Integer): LongBool; cdecl;  
  246.   lua_isstring:    function(L: lua_State; idx: Integer): LongBool; cdecl;  
  247.   lua_iscfunction: function(L: lua_State; idx: Integer): LongBool; cdecl;  
  248.   lua_isuserdata:  function(L: lua_State; idx: Integer): LongBool; cdecl;  
  249.   lua_type:        function(L: lua_State; idx: Integer): Integer; cdecl;  
  250.   lua_typename:    function(L: lua_State; tp: Integer): PAnsiChar; cdecl;  
  251.   
  252.   lua_equal:       function(L: lua_State; idx1, idx2: Integer): LongBool; cdecl;  
  253.   lua_rawequal:    function(L: lua_State; idx1, idx2: Integer): LongBool; cdecl;  
  254.   lua_lessthan:    function(L: lua_State; idx1, idx2: Integer): LongBool; cdecl;  
  255.   
  256.   lua_tonumber:    function(L: lua_State; idx: Integer): lua_Number; cdecl;  
  257.   lua_tointeger:   function(L: lua_State; idx: Integer): lua_Integer; cdecl;  
  258.   lua_toboolean:   function(L: lua_State; idx: Integer): LongBool; cdecl;  
  259.   lua_tolstring:   function(L: lua_State; idx: Integer; var len: Cardinal): PAnsiChar; cdecl;  
  260.   lua_objlen:      function(L: lua_State; idx: Integer): Cardinal; cdecl;  
  261.   lua_tocfunction: function(L: lua_State; idx: Integer): lua_CFunction; cdecl;  
  262.   lua_touserdata:  function(L: lua_State; idx: Integer): Pointer; cdecl;  
  263.   lua_tothread:    function(L: lua_State; idx: Integer): lua_State; cdecl;  
  264.   lua_topointer:   function(L: lua_State; idx: Integer): Pointer; cdecl;  
  265.   
  266.   (* 
  267.   ** push functions (C/Pascal -> stack) 
  268.   *)  
  269.   lua_pushnil:      procedure(L: lua_State); cdecl;  
  270.   lua_pushnumber:   procedure(L: lua_State; n: lua_Number); cdecl;  
  271.   lua_pushinteger:  procedure(L: lua_State; n: lua_Integer); cdecl;  
  272.   lua_pushlstring:  procedure(L: lua_State; s: PAnsiChar; len: Cardinal); cdecl;  
  273.   lua_pushstring:   procedure(L: lua_State; s: PAnsiChar); cdecl;  
  274.   lua_pushvfstring: function(L: lua_State; fmt, argp: PAnsiChar): PAnsiChar; cdecl;  
  275.   
  276.   lua_pushfstring:  function(L: lua_State; fmt: PAnsiChar; args: array of const): PAnsiChar; cdecl;  
  277.   lua_pushcclosure: procedure(L: lua_State; fn: lua_CFunction; n: Integer); cdecl;  
  278.   lua_pushboolean:  procedure(L: lua_State; b: LongBool); cdecl;  
  279.   lua_pushlightuserdata: procedure(L: lua_State; p: Pointer); cdecl;  
  280.   lua_pushthread:   function(L: lua_State): Integer; cdecl;  
  281.   
  282.   (* 
  283.   ** get functions (Lua -> stack) 
  284.   *)  
  285.   lua_gettable:     procedure(L: lua_State; idx: Integer); cdecl;  
  286.   lua_getfield:     procedure(L: lua_State; idx: Integer; k: PAnsiChar); cdecl;  
  287.   lua_rawget:       procedure(L: lua_State; idx: Integer); cdecl;  
  288.   lua_rawgeti:      procedure(L: lua_State; idx, n: Integer); cdecl;  
  289.   lua_createtable:  procedure(L: lua_State; narr, nrec: Integer); cdecl;  
  290.   lua_newuserdata:  function(L: lua_State; size: Cardinal): Pointer; cdecl;  
  291.   lua_getmetatable: function(L: lua_State; idx: Integer): LongBool; cdecl;  
  292.   lua_getfenv:      procedure(L: lua_State; idx: Integer); cdecl;  
  293.   
  294.   (* 
  295.   ** set functions (stack -> Lua) 
  296.   *)  
  297.   lua_settable:     procedure(L: lua_State; idx: Integer); cdecl;  
  298.   lua_setfield:     procedure(L: lua_State; idx: Integer; k: PAnsiChar ); cdecl;  
  299.   lua_rawset:       procedure(L: lua_State; idx: Integer); cdecl;  
  300.   lua_rawseti:      procedure(L: lua_State; idx, n: Integer); cdecl;  
  301.   lua_setmetatable: function(L: lua_State; idx: Integer): LongBool; cdecl;  
  302.   lua_setfenv:      function(L: lua_State; idx: Integer): LongBool; cdecl;  
  303.   
  304.   (* 
  305.   ** `load' and `call' functions (load and run Lua code) 
  306.   *)  
  307.   lua_call:   procedure(L: lua_State; nargs, nresults: Integer); cdecl;  
  308.   lua_pcall:  function(L: lua_State; nargs, nresults, errfunc: Integer): Integer; cdecl;  
  309.   lua_cpcall: function(L: lua_State; func: lua_CFunction; ud: Pointer): Integer; cdecl;  
  310.   lua_load:   function(L: lua_State; reader: lua_Reader; data: Pointer; chunkname: PAnsiChar): Integer; cdecl;  
  311.   lua_dump:   function(L: lua_State; writer: lua_Writer; data: Pointer): Integer; cdecl;  
  312.   
  313.   (* 
  314.   ** coroutine functions 
  315.   *)  
  316.   lua_yield:  function(L: lua_State; nresults: Integer): Integer; cdecl;  
  317.   lua_resume: function(L: lua_State; narg: Integer): Integer; cdecl;  
  318.   lua_status: function(L: lua_State): Integer; cdecl;  
  319.   
  320.   (* 
  321.   ** garbage-collection functions 
  322.   *)  
  323.   lua_gc: function(L: lua_State; what, data: Integer): Integer; cdecl;  
  324.   
  325.   (* 
  326.   ** miscellaneous functions 
  327.   *)  
  328.   
  329.   lua_error:  function(L: lua_State): Integer; cdecl;  
  330.   lua_next:   function(L: lua_State; idx: Integer): Integer; cdecl;  
  331.   lua_concat: procedure(L: lua_State; n: Integer); cdecl;  
  332.   
  333.   lua_getallocf: function(L: lua_State; ud: Pointer): lua_Alloc; cdecl;  
  334.   lua_setallocf: procedure(L: lua_State; f: lua_Alloc; ud: Pointer); cdecl;  
  335.   
  336.   (* 
  337.   ** {====================================================================== 
  338.   ** Debug API 
  339.   ** ======================================================================= 
  340.   *)  
  341.   
  342.   lua_getstack:   function(L: lua_State; level: Integer; var ar: lua_Debug): Integer; cdecl;  
  343.   lua_getinfo:    function(L: lua_State; what: PAnsiChar; var ar: lua_Debug): Integer; cdecl;  
  344.   lua_getlocal:   function(L: lua_State; var ar: lua_Debug; n: Integer): PAnsiChar; cdecl;  
  345.   lua_setlocal:   function(L: lua_State; var ar: lua_Debug; n: Integer): PAnsiChar; cdecl;  
  346.   lua_getupvalue: function(L: lua_State; funcindex, n: Integer): PAnsiChar; cdecl;  
  347.   lua_setupvalue: function(L: lua_State; funcindex, n: Integer): PAnsiChar; cdecl;  
  348.   
  349.   lua_sethook:      function(L: lua_State; func: lua_Hook; mask, count: Integer): Integer; cdecl;  
  350.   lua_gethook:      function(L: lua_State): lua_Hook; cdecl;  
  351.   lua_gethookmask:  function(L: lua_State): Integer; cdecl;  
  352.   lua_gethookcount: function(L: lua_State): Integer; cdecl;  
  353.   
  354.   (* lua libraries *)  
  355.   luaopen_base:    function(L: lua_State): Integer; cdecl;  
  356.   luaopen_debug:   function(L: lua_State): Integer; cdecl;  
  357.   luaopen_io:      function(L: lua_State): Integer; cdecl;  
  358.   luaopen_math:    function(L: lua_State): Integer; cdecl;  
  359.   luaopen_os:      function(L: lua_State): Integer; cdecl;  
  360.   luaopen_package: function(L: lua_State): Integer; cdecl;  
  361.   luaopen_string:  function(L: lua_State): Integer; cdecl;  
  362.   luaopen_table:   function(L: lua_State): Integer; cdecl;  
  363.   (* open all previous libraries *)  
  364.   luaL_openlibs:   procedure(L: lua_State); cdecl;  
  365.   
  366.   luaL_register:     procedure(L: lua_State; libname: PAnsiChar; lr: PluaL_reg); cdecl;  
  367.   luaL_getmetafield: function(L: lua_State; obj: Integer; e: PAnsiChar): Integer; cdecl;  
  368.   luaL_callmeta:     function(L: lua_State; obj: Integer; e: PAnsiChar): Integer; cdecl;  
  369.   luaL_typerror:     function(L: lua_State; narg: Integer; tname: PAnsiChar): Integer; cdecl;  
  370.   luaL_argerror:     function(L: lua_State; narg: Integer; extramsg: PAnsiChar): Integer; cdecl;  
  371.   luaL_checklstring: function(L: lua_State; narg: Integer; var len: Cardinal): PAnsiChar; cdecl;  
  372.   luaL_optlstring:   function(L: lua_State; narg: Integer; d: PAnsiChar; var len: Cardinal): PAnsiChar; cdecl;  
  373.   luaL_checknumber:  function(L: lua_State; narg: Integer): lua_Number; cdecl;  
  374.   luaL_optnumber:    function(L: lua_State; narg: Integer; d: lua_Number): lua_Number; cdecl;  
  375.   
  376.   luaL_checkinteger: function(L: lua_State; narg: Integer): lua_Integer; cdecl;  
  377.   luaL_optinteger:   function(L: lua_State; narg: Integer; d: lua_Integer): lua_Integer; cdecl;  
  378.   
  379.   luaL_checkstack: procedure(L: lua_State; sz: Integer; msg: PAnsiChar); cdecl;  
  380.   luaL_checktype:  procedure(L: lua_State; narg, t: Integer); cdecl;  
  381.   luaL_checkany:   procedure(L: lua_State; narg: Integer); cdecl;  
  382.   
  383.   luaL_newmetatable: function(L: lua_State; tname: PAnsiChar): Integer; cdecl;  
  384.   luaL_checkudata:   function(L: lua_State; narg: Integer; tname: PAnsiChar): Pointer; cdecl;  
  385.   
  386.   luaL_checkoption: function(L: lua_State; narg: Integer; def: PAnsiChar; lst: array of PAnsiChar): Integer; cdecl;  
  387.   
  388.   luaL_where: procedure(L: lua_State; lvl: Integer); cdecl;  
  389.   luaL_error: function(L: lua_State; fmt: PAnsiChar; args: array of const): Integer; cdecl;  
  390.   
  391.   luaL_ref:   function(L: lua_State; t: Integer): Integer; cdecl;  
  392.   luaL_unref: procedure(L: lua_State; t, ref: Integer); cdecl;  
  393.   
  394. {$ifdef LUA_COMPAT_GETN}  
  395.   luaL_getn: function(L: lua_State; t: Integer): Integer; cdecl;  
  396.   luaL_setn: procedure(L: lua_State; t, n: Integer); cdecl;  
  397. {$endif}  
  398.   
  399.   luaL_loadfile:   function(L: lua_State; filename: PAnsiChar): Integer; cdecl;  
  400.   luaL_loadbuffer: function(L: lua_State; buff: PAnsiChar; sz: Cardinal; name: PAnsiChar): Integer; cdecl;  
  401.   luaL_loadstring: function(L: lua_State; s: PAnsiChar): Integer; cdecl;  
  402.   
  403.   luaL_newstate:  function(): lua_State; cdecl;  
  404.   luaL_gsub:      function(L: lua_State; s, p, r: PAnsiChar): PAnsiChar; cdecl;  
  405.   luaL_findtable: function(L: lua_State; idx: Integer; fname: PAnsiChar; szhint: Integer): PAnsiChar; cdecl;  
  406.   
  407.   luaL_buffinit:   procedure(L: lua_State; var B: luaL_Buffer); cdecl;  
  408.   luaL_prepbuffer: function(var B: luaL_Buffer): PAnsiChar; cdecl;  
  409.   luaL_addlstring: procedure(var B: luaL_Buffer; s: PAnsiChar; l: Cardinal); cdecl;  
  410.   luaL_addstring:  procedure(var B: luaL_Buffer; s: PAnsiChar); cdecl;  
  411.   luaL_addvalue:   procedure(var B: luaL_Buffer); cdecl;  
  412.   luaL_pushresult: procedure(var B: luaL_Buffer); cdecl;  
  413.   
  414.   (* 
  415.   ** =============================================================== 
  416.   ** some useful macros 
  417.   ** =============================================================== 
  418.   *)  
  419.   
  420. {$ifndef LUA_COMPAT_GETN}  
  421.   function  luaL_getn(L: lua_State; t: Integer): Integer;  
  422.   procedure luaL_setn(L: lua_State; t, n: Integer);   

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
lua 的简单使用发布时间:2022-07-22
下一篇:
编译lua动态库发布时间:2022-07-22
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap