DEADSOFTWARE

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