lua.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. (******************************************************************************
  2. * *
  3. * File: lua.pas *
  4. * Authors: TeCGraf (C headers + actual Lua libraries) *
  5. * Lavergne Thomas (original translation to Pascal) *
  6. * Bram Kuijvenhoven (update to Lua 5.1.1 for FreePascal) *
  7. * Description: Basic Lua library *
  8. * *
  9. ******************************************************************************)
  10. (*
  11. ** $Id: lua.h,v 1.175 2003/03/18 12:31:39 roberto Exp $
  12. ** Lua - An Extensible Extension Language
  13. ** TeCGraf: Computer Graphics Technology Group, PUC-Rio, Brazil
  14. ** http://www.lua.org mailto:[email protected]
  15. ** See Copyright Notice at the end of this file
  16. *)
  17. (*
  18. ** Updated to Lua 5.1.1 by Bram Kuijvenhoven (bram at kuijvenhoven dot net),
  19. ** Hexis BV (http://www.hexis.nl), the Netherlands
  20. ** Notes:
  21. ** - Only tested with FPC (FreePascal Compiler)
  22. ** - Using LuaBinaries styled DLL/SO names, which include version names
  23. ** - LUA_YIELD was suffixed by '_' for avoiding name collision
  24. *)
  25. (*
  26. ** Translated to pascal by Lavergne Thomas
  27. ** Notes :
  28. ** - Pointers type was prefixed with 'P'
  29. ** - lua_upvalueindex constant was transformed to function
  30. ** - Some compatibility function was isolated because with it you must have
  31. ** lualib.
  32. ** - LUA_VERSION was suffixed by '_' for avoiding name collision.
  33. ** Bug reports :
  34. ** - [email protected]
  35. ** In french or in english
  36. *)
  37. {$IFDEF FPC}{$MODE OBJFPC}{$H+}{$ENDIF}
  38. unit lua;
  39. interface
  40. const
  41. {$IFDEF UNIX}
  42. LUA_NAME = 'liblua5.1.so';
  43. LUA_LIB_NAME = 'liblua5.1.so';
  44. {$ELSE}
  45. LUA_NAME = 'lua5.1.dll';
  46. LUA_LIB_NAME = 'lua5.1.dll';
  47. {$ENDIF}
  48. type
  49. size_t = Cardinal;
  50. Psize_t = ^size_t;
  51. const
  52. LUA_VERSION = 'Lua 5.1';
  53. LUA_RELEASE = 'Lua 5.1.1';
  54. LUA_VERSION_NUM = 501;
  55. LUA_COPYRIGHT = 'Copyright (C) 1994-2006 Lua.org, PUC-Rio';
  56. LUA_AUTHORS = 'R. Ierusalimschy, L. H. de Figueiredo & W. Celes';
  57. (* option for multiple returns in `lua_pcall' and `lua_call' *)
  58. LUA_MULTRET = -1;
  59. (*
  60. ** pseudo-indices
  61. *)
  62. LUA_REGISTRYINDEX = -10000;
  63. LUA_ENVIRONINDEX = -10001;
  64. LUA_GLOBALSINDEX = -10002;
  65. function lua_upvalueindex(I: Integer): Integer;
  66. const
  67. (* thread status; 0 is OK *)
  68. LUA_YIELD_ = 1;
  69. LUA_ERRRUN = 2;
  70. LUA_ERRSYNTAX = 3;
  71. LUA_ERRMEM = 4;
  72. LUA_ERRERR = 5;
  73. type
  74. Plua_State = Pointer;
  75. lua_CFunction = function(L: Plua_State): Integer; cdecl;
  76. (*
  77. ** functions that read/write blocks when loading/dumping Lua chunks
  78. *)
  79. type
  80. lua_Reader = function(L: Plua_State; ud: Pointer; sz: Psize_t): PChar; cdecl;
  81. lua_Writer = function(L: Plua_State; const p: Pointer; sz: size_t; ud: Pointer): Integer; cdecl;
  82. (*
  83. ** prototype for memory-allocation functions
  84. *)
  85. lua_Alloc = procedure(ud, ptr: Pointer; osize, nsize: size_t); cdecl;
  86. (*
  87. ** basic types
  88. *)
  89. const
  90. LUA_TNONE = -1;
  91. LUA_TNIL = 0;
  92. LUA_TBOOLEAN = 1;
  93. LUA_TLIGHTUSERDATA = 2;
  94. LUA_TNUMBER = 3;
  95. LUA_TSTRING = 4;
  96. LUA_TTABLE = 5;
  97. LUA_TFUNCTION = 6;
  98. LUA_TUSERDATA = 7;
  99. LUA_TTHREAD = 8;
  100. (* minimum Lua stack available to a C function *)
  101. LUA_MINSTACK = 20;
  102. type
  103. (* Type of Numbers in Lua *)
  104. lua_Number = Double;
  105. lua_Integer = PtrInt;
  106. (*
  107. ** state manipulation
  108. *)
  109. function lua_newstate(f: lua_Alloc; ud: Pointer): Plua_state; cdecl;
  110. procedure lua_close(L: Plua_State); cdecl;
  111. function lua_newthread(L: Plua_State): Plua_State; cdecl;
  112. function lua_atpanic(L: Plua_State; panicf: lua_CFunction): lua_CFunction; cdecl;
  113. (*
  114. ** basic stack manipulation
  115. *)
  116. function lua_gettop(L: Plua_State): Integer; cdecl;
  117. procedure lua_settop(L: Plua_State; idx: Integer); cdecl;
  118. procedure lua_pushvalue(L: Plua_State; Idx: Integer); cdecl;
  119. procedure lua_remove(L: Plua_State; idx: Integer); cdecl;
  120. procedure lua_insert(L: Plua_State; idx: Integer); cdecl;
  121. procedure lua_replace(L: Plua_State; idx: Integer); cdecl;
  122. function lua_checkstack(L: Plua_State; sz: Integer): LongBool; cdecl;
  123. procedure lua_xmove(from, to_: Plua_State; n: Integer); cdecl;
  124. (*
  125. ** access functions (stack -> C)
  126. *)
  127. function lua_isnumber(L: Plua_State; idx: Integer): LongBool; cdecl;
  128. function lua_isstring(L: Plua_State; idx: Integer): LongBool; cdecl;
  129. function lua_iscfunction(L: Plua_State; idx: Integer): LongBool; cdecl;
  130. function lua_isuserdata(L: Plua_State; idx: Integer): LongBool; cdecl;
  131. function lua_type(L: Plua_State; idx: Integer): Integer; cdecl;
  132. function lua_typename(L: Plua_State; tp: Integer): PChar; cdecl;
  133. function lua_equal(L: Plua_State; idx1, idx2: Integer): LongBool; cdecl;
  134. function lua_rawequal(L: Plua_State; idx1, idx2: Integer): LongBool; cdecl;
  135. function lua_lessthan(L: Plua_State; idx1, idx2: Integer): LongBool; cdecl;
  136. function lua_tonumber(L: Plua_State; idx: Integer): lua_Number; cdecl;
  137. function lua_tointeger(L: Plua_State; idx: Integer): lua_Integer; cdecl;
  138. function lua_toboolean(L: Plua_State; idx: Integer): LongBool; cdecl;
  139. function lua_tolstring(L: Plua_State; idx: Integer; len: Psize_t): PChar; cdecl;
  140. function lua_objlen(L: Plua_State; idx: Integer): size_t; cdecl;
  141. function lua_tocfunction(L: Plua_State; idx: Integer): lua_CFunction; cdecl;
  142. function lua_touserdata(L: Plua_State; idx: Integer): Pointer; cdecl;
  143. function lua_tothread(L: Plua_State; idx: Integer): Plua_State; cdecl;
  144. function lua_topointer(L: Plua_State; idx: Integer): Pointer; cdecl;
  145. (*
  146. ** push functions (C -> stack)
  147. *)
  148. procedure lua_pushnil(L: Plua_State); cdecl;
  149. procedure lua_pushnumber(L: Plua_State; n: lua_Number); cdecl;
  150. procedure lua_pushinteger(L: Plua_State; n: lua_Integer); cdecl;
  151. procedure lua_pushlstring(L: Plua_State; const s: PChar; l_: size_t); cdecl;
  152. procedure lua_pushstring(L: Plua_State; const s: PChar); cdecl;
  153. function lua_pushvfstring(L: Plua_State; const fmt: PChar; argp: Pointer): PChar; cdecl;
  154. function lua_pushfstring(L: Plua_State; const fmt: PChar): PChar; cdecl; varargs;
  155. procedure lua_pushcclosure(L: Plua_State; fn: lua_CFunction; n: Integer); cdecl;
  156. procedure lua_pushboolean(L: Plua_State; b: LongBool); cdecl;
  157. procedure lua_pushlightuserdata(L: Plua_State; p: Pointer); cdecl;
  158. procedure lua_pushthread(L: Plua_State); cdecl;
  159. (*
  160. ** get functions (Lua -> stack)
  161. *)
  162. procedure lua_gettable(L: Plua_State; idx: Integer); cdecl;
  163. procedure lua_getfield(L: Plua_state; idx: Integer; k: PChar); cdecl;
  164. procedure lua_rawget(L: Plua_State; idx: Integer); cdecl;
  165. procedure lua_rawgeti(L: Plua_State; idx, n: Integer); cdecl;
  166. procedure lua_createtable(L: Plua_State; narr, nrec: Integer); cdecl;
  167. function lua_newuserdata(L: Plua_State; sz: size_t): Pointer; cdecl;
  168. function lua_getmetatable(L: Plua_State; objindex: Integer): Integer; cdecl;
  169. procedure lua_getfenv(L: Plua_State; idx: Integer); cdecl;
  170. (*
  171. ** set functions (stack -> Lua)
  172. *)
  173. procedure lua_settable(L: Plua_State; idx: Integer); cdecl;
  174. procedure lua_setfield(L: Plua_State; idx: Integer; k: PChar); cdecl;
  175. procedure lua_rawset(L: Plua_State; idx: Integer); cdecl;
  176. procedure lua_rawseti(L: Plua_State; idx, n: Integer); cdecl;
  177. function lua_setmetatable(L: Plua_State; objindex: Integer): Integer; cdecl;
  178. function lua_setfenv(L: Plua_State; idx: Integer): Integer; cdecl;
  179. (*
  180. ** `load' and `call' functions (load and run Lua code)
  181. *)
  182. procedure lua_call(L: Plua_State; nargs, nresults: Integer); cdecl;
  183. function lua_pcall(L: Plua_State; nargs, nresults, errf: Integer): Integer; cdecl;
  184. function lua_cpcall(L: Plua_State; func: lua_CFunction; ud: Pointer): Integer; cdecl;
  185. function lua_load(L: Plua_State; reader: lua_Reader; dt: Pointer; const chunkname: PChar): Integer; cdecl;
  186. function lua_dump(L: Plua_State; writer: lua_Writer; data: Pointer): Integer; cdecl;
  187. (*
  188. ** coroutine functions
  189. *)
  190. function lua_yield(L: Plua_State; nresults: Integer): Integer; cdecl;
  191. function lua_resume(L: Plua_State; narg: Integer): Integer; cdecl;
  192. function lua_status(L: Plua_State): Integer; cdecl;
  193. (*
  194. ** Garbage-collection functions and options
  195. *)
  196. const
  197. LUA_GCSTOP = 0;
  198. LUA_GCRESTART = 1;
  199. LUA_GCCOLLECT = 2;
  200. LUA_GCCOUNT = 3;
  201. LUA_GCCOUNTB = 4;
  202. LUA_GCSTEP = 5;
  203. LUA_GCSETPAUSE = 6;
  204. LUA_GCSETSTEPMUL = 7;
  205. function lua_gc(L: Plua_State; what, data: Integer): Integer; cdecl;
  206. (*
  207. ** miscellaneous functions
  208. *)
  209. function lua_error(L: Plua_State): Integer; cdecl;
  210. function lua_next(L: Plua_State; idx: Integer): Integer; cdecl;
  211. procedure lua_concat(L: Plua_State; n: Integer); cdecl;
  212. function lua_getallocf(L: Plua_State; ud: PPointer): lua_Alloc; cdecl;
  213. procedure lua_setallocf(L: Plua_State; f: lua_Alloc; ud: Pointer); cdecl;
  214. (*
  215. ** ===============================================================
  216. ** some useful macros
  217. ** ===============================================================
  218. *)
  219. procedure lua_pop(L: Plua_State; n: Integer);
  220. procedure lua_newtable(L: Plua_state);
  221. procedure lua_register(L: Plua_State; const n: PChar; f: lua_CFunction);
  222. procedure lua_pushcfunction(L: Plua_State; f: lua_CFunction);
  223. function lua_strlen(L: Plua_state; i: Integer): size_t;
  224. function lua_isfunction(L: Plua_State; n: Integer): Boolean;
  225. function lua_istable(L: Plua_State; n: Integer): Boolean;
  226. function lua_islightuserdata(L: Plua_State; n: Integer): Boolean;
  227. function lua_isnil(L: Plua_State; n: Integer): Boolean;
  228. function lua_isboolean(L: Plua_State; n: Integer): Boolean;
  229. function lua_isthread(L: Plua_State; n: Integer): Boolean;
  230. function lua_isnone(L: Plua_State; n: Integer): Boolean;
  231. function lua_isnoneornil(L: Plua_State; n: Integer): Boolean;
  232. procedure lua_pushliteral(L: Plua_State; s: PChar);
  233. procedure lua_setglobal(L: Plua_State; const s: PChar);
  234. procedure lua_getglobal(L: Plua_State; const s: PChar);
  235. function lua_tostring(L: Plua_State; i: Integer): PChar;
  236. (*
  237. ** compatibility macros and functions
  238. *)
  239. procedure lua_getregistry(L: Plua_State);
  240. function lua_getgccount(L: Plua_State): Integer;
  241. type
  242. lua_Chunkreader = lua_Reader;
  243. lua_Chunkwriter = lua_Writer;
  244. (*
  245. ** {======================================================================
  246. ** Debug API
  247. ** =======================================================================
  248. *)
  249. const
  250. LUA_HOOKCALL = 0;
  251. LUA_HOOKRET = 1;
  252. LUA_HOOKLINE = 2;
  253. LUA_HOOKCOUNT = 3;
  254. LUA_HOOKTAILRET = 4;
  255. const
  256. LUA_MASKCALL = 1 shl Ord(LUA_HOOKCALL);
  257. LUA_MASKRET = 1 shl Ord(LUA_HOOKRET);
  258. LUA_MASKLINE = 1 shl Ord(LUA_HOOKLINE);
  259. LUA_MASKCOUNT = 1 shl Ord(LUA_HOOKCOUNT);
  260. const
  261. LUA_IDSIZE = 60;
  262. type
  263. lua_Debug = record (* activation record *)
  264. event: Integer;
  265. name: PChar; (* (n) *)
  266. namewhat: PChar; (* (n) `global', `local', `field', `method' *)
  267. what: PChar; (* (S) `Lua', `C', `main', `tail'*)
  268. source: PChar; (* (S) *)
  269. currentline: Integer; (* (l) *)
  270. nups: Integer; (* (u) number of upvalues *)
  271. linedefined: Integer; (* (S) *)
  272. lastlinedefined: Integer; (* (S) *)
  273. short_src: array[0..LUA_IDSIZE - 1] of Char; (* (S) *)
  274. (* private part *)
  275. i_ci: Integer; (* active function *)
  276. end;
  277. Plua_Debug = ^lua_Debug;
  278. lua_Hook = procedure(L: Plua_State; ar: Plua_Debug); cdecl;
  279. function lua_getstack(L: Plua_State; level: Integer; ar: Plua_Debug): Integer; cdecl;
  280. function lua_getinfo(L: Plua_State; const what: PChar; ar: Plua_Debug): Integer; cdecl;
  281. function lua_getlocal(L: Plua_State; const ar: Plua_Debug; n: Integer): PChar; cdecl;
  282. function lua_setlocal(L: Plua_State; const ar: Plua_Debug; n: Integer): PChar; cdecl;
  283. function lua_getupvalue(L: Plua_State; funcindex: Integer; n: Integer): PChar; cdecl;
  284. function lua_setupvalue(L: Plua_State; funcindex: Integer; n: Integer): PChar; cdecl;
  285. function lua_sethook(L: Plua_State; func: lua_Hook; mask: Integer; count: Integer): Integer; cdecl;
  286. //function lua_gethook(L: Plua_State): lua_Hook; cdecl;
  287. function lua_gethookmask(L: Plua_State): Integer; cdecl;
  288. function lua_gethookcount(L: Plua_State): Integer; cdecl;
  289. implementation
  290. function lua_upvalueindex(I: Integer): Integer;
  291. begin
  292. Result := LUA_GLOBALSINDEX - i;
  293. end;
  294. function lua_newstate(f: lua_Alloc; ud: Pointer): Plua_State; cdecl; external LUA_NAME;
  295. procedure lua_close(L: Plua_State); cdecl; external LUA_NAME;
  296. function lua_newthread(L: Plua_State): Plua_State; cdecl; external LUA_NAME;
  297. function lua_atpanic(L: Plua_State; panicf: lua_CFunction): lua_CFunction; cdecl; external LUA_NAME;
  298. function lua_gettop(L: Plua_State): Integer; cdecl; external LUA_NAME;
  299. procedure lua_settop(L: Plua_State; idx: Integer); cdecl; external LUA_NAME;
  300. procedure lua_pushvalue(L: Plua_State; Idx: Integer); cdecl; external LUA_NAME;
  301. procedure lua_remove(L: Plua_State; idx: Integer); cdecl; external LUA_NAME;
  302. procedure lua_insert(L: Plua_State; idx: Integer); cdecl; external LUA_NAME;
  303. procedure lua_replace(L: Plua_State; idx: Integer); cdecl; external LUA_NAME;
  304. function lua_checkstack(L: Plua_State; sz: Integer): LongBool; cdecl; external LUA_NAME;
  305. procedure lua_xmove(from, to_: Plua_State; n: Integer); cdecl; external LUA_NAME;
  306. function lua_isnumber(L: Plua_State; idx: Integer): LongBool; cdecl; external LUA_NAME;
  307. function lua_isstring(L: Plua_State; idx: Integer): LongBool; cdecl; external LUA_NAME;
  308. function lua_iscfunction(L: Plua_State; idx: Integer): LongBool; cdecl; external LUA_NAME;
  309. function lua_isuserdata(L: Plua_State; idx: Integer): LongBool; cdecl; external LUA_NAME;
  310. function lua_type(L: Plua_State; idx: Integer): Integer; cdecl; external LUA_NAME;
  311. function lua_typename(L: Plua_State; tp: Integer): PChar; cdecl; external LUA_NAME;
  312. function lua_equal(L: Plua_State; idx1, idx2: Integer): LongBool; cdecl; external LUA_NAME;
  313. function lua_rawequal(L: Plua_State; idx1, idx2: Integer): LongBool; cdecl; external LUA_NAME;
  314. function lua_lessthan(L: Plua_State; idx1, idx2: Integer): LongBool; cdecl; external LUA_NAME;
  315. function lua_tonumber(L: Plua_State; idx: Integer): lua_Number; cdecl; external LUA_NAME;
  316. function lua_tointeger(L: Plua_State; idx: Integer): lua_Integer; cdecl; external LUA_NAME;
  317. function lua_toboolean(L: Plua_State; idx: Integer): LongBool; cdecl; external LUA_NAME;
  318. function lua_tolstring(L: Plua_State; idx: Integer; len: Psize_t): PChar; cdecl; external LUA_NAME;
  319. function lua_objlen(L: Plua_State; idx: Integer): size_t; cdecl; external LUA_NAME;
  320. function lua_tocfunction(L: Plua_State; idx: Integer): lua_CFunction; cdecl; external LUA_NAME;
  321. function lua_touserdata(L: Plua_State; idx: Integer): Pointer; cdecl; external LUA_NAME;
  322. function lua_tothread(L: Plua_State; idx: Integer): Plua_State; cdecl; external LUA_NAME;
  323. function lua_topointer(L: Plua_State; idx: Integer): Pointer; cdecl; external LUA_NAME;
  324. procedure lua_pushnil(L: Plua_State); cdecl; external LUA_NAME;
  325. procedure lua_pushnumber(L: Plua_State; n: lua_Number); cdecl; external LUA_NAME;
  326. procedure lua_pushinteger(L: Plua_State; n: lua_Integer); cdecl; external LUA_NAME;
  327. procedure lua_pushlstring(L: Plua_State; const s: PChar; l_: size_t); cdecl; external LUA_NAME;
  328. procedure lua_pushstring(L: Plua_State; const s: PChar); cdecl; external LUA_NAME;
  329. function lua_pushvfstring(L: Plua_State; const fmt: PChar; argp: Pointer): PChar; cdecl; external LUA_NAME;
  330. function lua_pushfstring(L: Plua_State; const fmt: PChar): PChar; cdecl; varargs; external LUA_NAME;
  331. procedure lua_pushcclosure(L: Plua_State; fn: lua_CFunction; n: Integer); cdecl; external LUA_NAME;
  332. procedure lua_pushboolean(L: Plua_State; b: LongBool); cdecl; external LUA_NAME;
  333. procedure lua_pushlightuserdata(L: Plua_State; p: Pointer); cdecl; external LUA_NAME;
  334. procedure lua_pushthread(L: Plua_State); cdecl; external LUA_NAME;
  335. procedure lua_gettable(L: Plua_State; idx: Integer); cdecl; external LUA_NAME;
  336. procedure lua_getfield(L: Plua_state; idx: Integer; k: PChar); cdecl; external LUA_NAME;
  337. procedure lua_rawget(L: Plua_State; idx: Integer); cdecl; external LUA_NAME;
  338. procedure lua_rawgeti(L: Plua_State; idx, n: Integer); cdecl; external LUA_NAME;
  339. procedure lua_createtable(L: Plua_State; narr, nrec: Integer); cdecl; external LUA_NAME;
  340. function lua_newuserdata(L: Plua_State; sz: size_t): Pointer; cdecl; external LUA_NAME;
  341. function lua_getmetatable(L: Plua_State; objindex: Integer): Integer; cdecl; external LUA_NAME;
  342. procedure lua_getfenv(L: Plua_State; idx: Integer); cdecl; external LUA_NAME;
  343. procedure lua_settable(L: Plua_State; idx: Integer); cdecl; external LUA_NAME;
  344. procedure lua_setfield(L: Plua_State; idx: Integer; k: PChar); cdecl; external LUA_NAME;
  345. procedure lua_rawset(L: Plua_State; idx: Integer); cdecl; external LUA_NAME;
  346. procedure lua_rawseti(L: Plua_State; idx, n: Integer); cdecl; external LUA_NAME;
  347. function lua_setmetatable(L: Plua_State; objindex: Integer): Integer; cdecl; external LUA_NAME;
  348. function lua_setfenv(L: Plua_State; idx: Integer): Integer; cdecl; external LUA_NAME;
  349. procedure lua_call(L: Plua_State; nargs, nresults: Integer); cdecl; external LUA_NAME;
  350. function lua_pcall(L: Plua_State; nargs, nresults, errf: Integer): Integer; cdecl; external LUA_NAME;
  351. function lua_cpcall(L: Plua_State; func: lua_CFunction; ud: Pointer): Integer; cdecl; external LUA_NAME;
  352. function lua_load(L: Plua_State; reader: lua_Reader; dt: Pointer; const chunkname: PChar): Integer; cdecl; external LUA_NAME;
  353. function lua_dump(L: Plua_State; writer: lua_Writer; data: Pointer): Integer; cdecl; external LUA_NAME;
  354. function lua_yield(L: Plua_State; nresults: Integer): Integer; cdecl; external LUA_NAME;
  355. function lua_resume(L: Plua_State; narg: Integer): Integer; cdecl; external LUA_NAME;
  356. function lua_status(L: Plua_State): Integer; cdecl; external LUA_NAME;
  357. function lua_gc(L: Plua_State; what, data: Integer): Integer; cdecl; external LUA_NAME;
  358. function lua_error(L: Plua_State): Integer; cdecl; external LUA_NAME;
  359. function lua_next(L: Plua_State; idx: Integer): Integer; cdecl; external LUA_NAME;
  360. procedure lua_concat(L: Plua_State; n: Integer); cdecl; external LUA_NAME;
  361. function lua_getallocf(L: Plua_State; ud: PPointer): lua_Alloc; cdecl; external LUA_NAME;
  362. procedure lua_setallocf(L: Plua_State; f: lua_Alloc; ud: Pointer); cdecl; external LUA_NAME;
  363. procedure lua_pop(L: Plua_State; n: Integer);
  364. begin
  365. lua_settop(L, -n - 1);
  366. end;
  367. procedure lua_newtable(L: Plua_State);
  368. begin
  369. lua_createtable(L, 0, 0);
  370. end;
  371. procedure lua_register(L: Plua_State; const n: PChar; f: lua_CFunction);
  372. begin
  373. lua_pushcfunction(L, f);
  374. lua_setglobal(L, n);
  375. end;
  376. procedure lua_pushcfunction(L: Plua_State; f: lua_CFunction);
  377. begin
  378. lua_pushcclosure(L, f, 0);
  379. end;
  380. function lua_strlen(L: Plua_State; i: Integer): size_t;
  381. begin
  382. Result := lua_objlen(L, i);
  383. end;
  384. function lua_isfunction(L: Plua_State; n: Integer): Boolean;
  385. begin
  386. Result := lua_type(L, n) = LUA_TFUNCTION;
  387. end;
  388. function lua_istable(L: Plua_State; n: Integer): Boolean;
  389. begin
  390. Result := lua_type(L, n) = LUA_TTABLE;
  391. end;
  392. function lua_islightuserdata(L: Plua_State; n: Integer): Boolean;
  393. begin
  394. Result := lua_type(L, n) = LUA_TLIGHTUSERDATA;
  395. end;
  396. function lua_isnil(L: Plua_State; n: Integer): Boolean;
  397. begin
  398. Result := lua_type(L, n) = LUA_TNIL;
  399. end;
  400. function lua_isboolean(L: Plua_State; n: Integer): Boolean;
  401. begin
  402. Result := lua_type(L, n) = LUA_TBOOLEAN;
  403. end;
  404. function lua_isthread(L: Plua_State; n: Integer): Boolean;
  405. begin
  406. Result := lua_type(L, n) = LUA_TTHREAD;
  407. end;
  408. function lua_isnone(L: Plua_State; n: Integer): Boolean;
  409. begin
  410. Result := lua_type(L, n) = LUA_TNONE;
  411. end;
  412. function lua_isnoneornil(L: Plua_State; n: Integer): Boolean;
  413. begin
  414. Result := lua_type(L, n) <= 0;
  415. end;
  416. procedure lua_pushliteral(L: Plua_State; s: PChar);
  417. begin
  418. lua_pushlstring(L, s, Length(s));
  419. end;
  420. procedure lua_setglobal(L: Plua_State; const s: PChar);
  421. begin
  422. lua_setfield(L, LUA_GLOBALSINDEX, s);
  423. end;
  424. procedure lua_getglobal(L: Plua_State; const s: PChar);
  425. begin
  426. lua_getfield(L, LUA_GLOBALSINDEX, s);
  427. end;
  428. function lua_tostring(L: Plua_State; i: Integer): PChar;
  429. begin
  430. Result := lua_tolstring(L, i, nil);
  431. end;
  432. procedure lua_getregistry(L: Plua_State);
  433. begin
  434. lua_pushvalue(L, LUA_REGISTRYINDEX);
  435. end;
  436. function lua_getgccount(L: Plua_State): Integer;
  437. begin
  438. Result := lua_gc(L, LUA_GCCOUNT, 0);
  439. end;
  440. (*
  441. ** {======================================================================
  442. ** Debug API
  443. ** =======================================================================
  444. *)
  445. function lua_getstack(L: Plua_State; level: Integer; ar: Plua_Debug): Integer; cdecl; external LUA_NAME;
  446. function lua_getinfo(L: Plua_State; const what: PChar; ar: Plua_Debug): Integer; cdecl; external LUA_NAME;
  447. function lua_getlocal(L: Plua_State; const ar: Plua_Debug; n: Integer): PChar; cdecl; external LUA_NAME;
  448. function lua_setlocal(L: Plua_State; const ar: Plua_Debug; n: Integer): PChar; cdecl; external LUA_NAME;
  449. function lua_getupvalue(L: Plua_State; funcindex: Integer; n: Integer): PChar; cdecl; external LUA_NAME;
  450. function lua_setupvalue(L: Plua_State; funcindex: Integer; n: Integer): PChar; cdecl; external LUA_NAME;
  451. function lua_sethook(L: Plua_State; func: lua_Hook; mask: Integer; count: Integer): Integer; cdecl; external LUA_NAME;
  452. //function lua_gethook(L: Plua_State): lua_Hook; cdecl; external LUA_NAME;
  453. function lua_gethookmask(L: Plua_State): Integer; cdecl; external LUA_NAME;
  454. function lua_gethookcount(L: Plua_State): Integer; cdecl; external LUA_NAME;
  455. (******************************************************************************
  456. * Copyright (C) 1994-2003 Tecgraf, PUC-Rio. All rights reserved.
  457. *
  458. * Permission is hereby granted, free of charge, to any person obtaining
  459. * a copy of this software and associated documentation files (the
  460. * "Software"), to deal in the Software without restriction, including
  461. * without limitation the rights to use, copy, modify, merge, publish,
  462. * distribute, sublicense, and/or sell copies of the Software, and to
  463. * permit persons to whom the Software is furnished to do so, subject to
  464. * the following conditions:
  465. *
  466. * The above copyright notice and this permission notice shall be
  467. * included in all copies or substantial portions of the Software.
  468. *
  469. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  470. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  471. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  472. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  473. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  474. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  475. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  476. ******************************************************************************)
  477. end.