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