1 module dlua.lua;
2 import dlua;
3 /*
4 ** $Id: lua.h,v 1.332.1.2 2018/06/13 16:58:17 roberto Exp $
5 ** Lua - A Scripting Language
6 ** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
7 ** See Copyright Notice at the end of this file
8 */
9 
10 import core.stdc.config;
11 import core.stdc.stdarg;
12 
13 import core.stdc.stddef;
14 
15 extern (C):
16 
17 enum LUA_VERSION_MAJOR = "5";
18 enum LUA_VERSION_MINOR = "3";
19 enum LUA_VERSION_NUM = 503;
20 enum LUA_VERSION_RELEASE = "5";
21 
22 enum LUA_AUTHORS = "R. Ierusalimschy, L. H. de Figueiredo, W. Celes";
23 
24 /* mark for precompiled code ('<esc>Lua') */
25 enum LUA_SIGNATURE = "\x1bLua";
26 
27 /* option for multiple returns in 'lua_pcall' and 'lua_call' */
28 enum LUA_MULTRET = -1;
29 
30 /*
31 ** Pseudo-indices
32 ** (-LUAI_MAXSTACK is the minimum valid index; we keep some free empty
33 ** space after that to help overflow detection)
34 */
35 enum LUA_REGISTRYINDEX = -LUAI_MAXSTACK - 1000;
36 
37 extern (D) auto lua_upvalueindex(T)(auto ref T i)
38 {
39     return LUA_REGISTRYINDEX - i;
40 }
41 
42 /* thread status */
43 enum LUA_OK = 0;
44 enum LUA_YIELD = 1;
45 enum LUA_ERRRUN = 2;
46 enum LUA_ERRSYNTAX = 3;
47 enum LUA_ERRMEM = 4;
48 enum LUA_ERRGCMM = 5;
49 enum LUA_ERRERR = 6;
50 
51 struct lua_State;
52 
53 /*
54 ** basic types
55 */
56 enum LUA_TNONE = -1;
57 
58 enum LUA_TNIL = 0;
59 enum LUA_TBOOLEAN = 1;
60 enum LUA_TLIGHTUSERDATA = 2;
61 enum LUA_TNUMBER = 3;
62 enum LUA_TSTRING = 4;
63 enum LUA_TTABLE = 5;
64 enum LUA_TFUNCTION = 6;
65 enum LUA_TUSERDATA = 7;
66 enum LUA_TTHREAD = 8;
67 
68 enum LUA_NUMTAGS = 9;
69 
70 /* minimum Lua stack available to a C function */
71 enum LUA_MINSTACK = 20;
72 
73 /* predefined values in the registry */
74 enum LUA_RIDX_MAINTHREAD = 1;
75 enum LUA_RIDX_GLOBALS = 2;
76 enum LUA_RIDX_LAST = LUA_RIDX_GLOBALS;
77 
78 /* type of numbers in Lua */
79 alias lua_Number = double;
80 
81 /* type for integer functions */
82 alias lua_Integer = long;
83 
84 /* unsigned integer type */
85 alias lua_Unsigned = ulong;
86 
87 /* type for continuation-function contexts */
88 alias lua_KContext = c_long;
89 
90 /*
91 ** Type for C functions registered with Lua
92 */
93 alias lua_CFunction = int function (lua_State* L);
94 
95 /*
96 ** Type for continuation functions
97 */
98 alias lua_KFunction = int function (lua_State* L, int status, lua_KContext ctx);
99 
100 /*
101 ** Type for functions that read/write blocks when loading/dumping Lua chunks
102 */
103 alias lua_Reader = const(char)* function (lua_State* L, void* ud, size_t* sz);
104 
105 alias lua_Writer = int function (lua_State* L, const(void)* p, size_t sz, void* ud);
106 
107 /*
108 ** Type for memory-allocation functions
109 */
110 alias lua_Alloc = void* function (void* ud, void* ptr, size_t osize, size_t nsize);
111 
112 /*
113 ** generic extra include file
114 */
115 
116 /*
117 ** RCS ident string
118 */
119 extern __gshared const(char)[] lua_ident;
120 
121 /*
122 ** state manipulation
123 */
124 lua_State* lua_newstate (lua_Alloc f, void* ud);
125 void lua_close (lua_State* L);
126 lua_State* lua_newthread (lua_State* L);
127 
128 lua_CFunction lua_atpanic (lua_State* L, lua_CFunction panicf);
129 
130 const(lua_Number)* lua_version (lua_State* L);
131 
132 /*
133 ** basic stack manipulation
134 */
135 int lua_absindex (lua_State* L, int idx);
136 int lua_gettop (lua_State* L);
137 void lua_settop (lua_State* L, int idx);
138 void lua_pushvalue (lua_State* L, int idx);
139 void lua_rotate (lua_State* L, int idx, int n);
140 void lua_copy (lua_State* L, int fromidx, int toidx);
141 int lua_checkstack (lua_State* L, int n);
142 
143 void lua_xmove (lua_State* from, lua_State* to, int n);
144 
145 /*
146 ** access functions (stack -> C)
147 */
148 
149 int lua_isnumber (lua_State* L, int idx);
150 int lua_isstring (lua_State* L, int idx);
151 int lua_iscfunction (lua_State* L, int idx);
152 int lua_isinteger (lua_State* L, int idx);
153 int lua_isuserdata (lua_State* L, int idx);
154 int lua_type (lua_State* L, int idx);
155 const(char)* lua_typename (lua_State* L, int tp);
156 
157 lua_Number lua_tonumberx (lua_State* L, int idx, int* isnum);
158 lua_Integer lua_tointegerx (lua_State* L, int idx, int* isnum);
159 int lua_toboolean (lua_State* L, int idx);
160 const(char)* lua_tolstring (lua_State* L, int idx, size_t* len);
161 size_t lua_rawlen (lua_State* L, int idx);
162 lua_CFunction lua_tocfunction (lua_State* L, int idx);
163 void* lua_touserdata (lua_State* L, int idx);
164 lua_State* lua_tothread (lua_State* L, int idx);
165 const(void)* lua_topointer (lua_State* L, int idx);
166 
167 /*
168 ** Comparison and arithmetic functions
169 */
170 
171 enum LUA_OPADD = 0; /* ORDER TM, ORDER OP */
172 enum LUA_OPSUB = 1;
173 enum LUA_OPMUL = 2;
174 enum LUA_OPMOD = 3;
175 enum LUA_OPPOW = 4;
176 enum LUA_OPDIV = 5;
177 enum LUA_OPIDIV = 6;
178 enum LUA_OPBAND = 7;
179 enum LUA_OPBOR = 8;
180 enum LUA_OPBXOR = 9;
181 enum LUA_OPSHL = 10;
182 enum LUA_OPSHR = 11;
183 enum LUA_OPUNM = 12;
184 enum LUA_OPBNOT = 13;
185 
186 void lua_arith (lua_State* L, int op);
187 
188 enum LUA_OPEQ = 0;
189 enum LUA_OPLT = 1;
190 enum LUA_OPLE = 2;
191 
192 int lua_rawequal (lua_State* L, int idx1, int idx2);
193 int lua_compare (lua_State* L, int idx1, int idx2, int op);
194 
195 /*
196 ** push functions (C -> stack)
197 */
198 void lua_pushnil (lua_State* L);
199 void lua_pushnumber (lua_State* L, lua_Number n);
200 void lua_pushinteger (lua_State* L, lua_Integer n);
201 const(char)* lua_pushlstring (lua_State* L, const(char)* s, size_t len);
202 const(char)* lua_pushstring (lua_State* L, const(char)* s);
203 const(char)* lua_pushvfstring (lua_State* L, const(char)* fmt, va_list argp);
204 const(char)* lua_pushfstring (lua_State* L, const(char)* fmt, ...);
205 void lua_pushcclosure (lua_State* L, lua_CFunction fn, int n);
206 void lua_pushboolean (lua_State* L, int b);
207 void lua_pushlightuserdata (lua_State* L, void* p);
208 int lua_pushthread (lua_State* L);
209 
210 /*
211 ** get functions (Lua -> stack)
212 */
213 int lua_getglobal (lua_State* L, const(char)* name);
214 int lua_gettable (lua_State* L, int idx);
215 int lua_getfield (lua_State* L, int idx, const(char)* k);
216 int lua_geti (lua_State* L, int idx, lua_Integer n);
217 int lua_rawget (lua_State* L, int idx);
218 int lua_rawgeti (lua_State* L, int idx, lua_Integer n);
219 int lua_rawgetp (lua_State* L, int idx, const(void)* p);
220 
221 void lua_createtable (lua_State* L, int narr, int nrec);
222 void* lua_newuserdata (lua_State* L, size_t sz);
223 int lua_getmetatable (lua_State* L, int objindex);
224 int lua_getuservalue (lua_State* L, int idx);
225 
226 /*
227 ** set functions (stack -> Lua)
228 */
229 void lua_setglobal (lua_State* L, const(char)* name);
230 void lua_settable (lua_State* L, int idx);
231 void lua_setfield (lua_State* L, int idx, const(char)* k);
232 void lua_seti (lua_State* L, int idx, lua_Integer n);
233 void lua_rawset (lua_State* L, int idx);
234 void lua_rawseti (lua_State* L, int idx, lua_Integer n);
235 void lua_rawsetp (lua_State* L, int idx, const(void)* p);
236 int lua_setmetatable (lua_State* L, int objindex);
237 void lua_setuservalue (lua_State* L, int idx);
238 
239 /*
240 ** 'load' and 'call' functions (load and run Lua code)
241 */
242 void lua_callk (
243     lua_State* L,
244     int nargs,
245     int nresults,
246     lua_KContext ctx,
247     lua_KFunction k);
248 
249 extern (D) auto lua_call(T0, T1, T2)(auto ref T0 L, auto ref T1 n, auto ref T2 r)
250 {
251     return lua_callk(L, n, r, 0, null);
252 }
253 
254 int lua_pcallk (
255     lua_State* L,
256     int nargs,
257     int nresults,
258     int errfunc,
259     lua_KContext ctx,
260     lua_KFunction k);
261 
262 extern (D) auto lua_pcall(T0, T1, T2, T3)(auto ref T0 L, auto ref T1 n, auto ref T2 r, auto ref T3 f)
263 {
264     return lua_pcallk(L, n, r, f, 0, null);
265 }
266 
267 int lua_load (
268     lua_State* L,
269     lua_Reader reader,
270     void* dt,
271     const(char)* chunkname,
272     const(char)* mode);
273 
274 int lua_dump (lua_State* L, lua_Writer writer, void* data, int strip);
275 
276 /*
277 ** coroutine functions
278 */
279 int lua_yieldk (lua_State* L, int nresults, lua_KContext ctx, lua_KFunction k);
280 int lua_resume (lua_State* L, lua_State* from, int narg);
281 int lua_status (lua_State* L);
282 int lua_isyieldable (lua_State* L);
283 
284 extern (D) auto lua_yield(T0, T1)(auto ref T0 L, auto ref T1 n)
285 {
286     return lua_yieldk(L, n, 0, null);
287 }
288 
289 /*
290 ** garbage-collection function and options
291 */
292 
293 enum LUA_GCSTOP = 0;
294 enum LUA_GCRESTART = 1;
295 enum LUA_GCCOLLECT = 2;
296 enum LUA_GCCOUNT = 3;
297 enum LUA_GCCOUNTB = 4;
298 enum LUA_GCSTEP = 5;
299 enum LUA_GCSETPAUSE = 6;
300 enum LUA_GCSETSTEPMUL = 7;
301 enum LUA_GCISRUNNING = 9;
302 
303 int lua_gc (lua_State* L, int what, int data);
304 
305 /*
306 ** miscellaneous functions
307 */
308 
309 int lua_error (lua_State* L);
310 
311 int lua_next (lua_State* L, int idx);
312 
313 void lua_concat (lua_State* L, int n);
314 void lua_len (lua_State* L, int idx);
315 
316 size_t lua_stringtonumber (lua_State* L, const(char)* s);
317 
318 lua_Alloc lua_getallocf (lua_State* L, void** ud);
319 void lua_setallocf (lua_State* L, lua_Alloc f, void* ud);
320 
321 /*
322 ** {==============================================================
323 ** some useful macros
324 ** ===============================================================
325 */
326 
327 extern (D) auto lua_getextraspace(T)(auto ref T L)
328 {
329     return cast(void*) cast(char*) L - LUA_EXTRASPACE;
330 }
331 
332 extern (D) auto lua_tonumber(T0, T1)(auto ref T0 L, auto ref T1 i)
333 {
334     return lua_tonumberx(L, i, null);
335 }
336 
337 extern (D) auto lua_tointeger(T0, T1)(auto ref T0 L, auto ref T1 i)
338 {
339     return lua_tointegerx(L, i, null);
340 }
341 
342 extern (D) auto lua_pop(T0, T1)(auto ref T0 L, auto ref T1 n)
343 {
344     return lua_settop(L, -n - 1);
345 }
346 
347 extern (D) auto lua_newtable(T)(auto ref T L)
348 {
349     return lua_createtable(L, 0, 0);
350 }
351 
352 extern (D) auto lua_pushcfunction(T0, T1)(auto ref T0 L, auto ref T1 f)
353 {
354     return lua_pushcclosure(L, f, 0);
355 }
356 
357 extern (D) auto lua_isfunction(T0, T1)(auto ref T0 L, auto ref T1 n)
358 {
359     return lua_type(L, n) == LUA_TFUNCTION;
360 }
361 
362 extern (D) auto lua_istable(T0, T1)(auto ref T0 L, auto ref T1 n)
363 {
364     return lua_type(L, n) == LUA_TTABLE;
365 }
366 
367 extern (D) auto lua_islightuserdata(T0, T1)(auto ref T0 L, auto ref T1 n)
368 {
369     return lua_type(L, n) == LUA_TLIGHTUSERDATA;
370 }
371 
372 extern (D) auto lua_isnil(T0, T1)(auto ref T0 L, auto ref T1 n)
373 {
374     return lua_type(L, n) == LUA_TNIL;
375 }
376 
377 extern (D) auto lua_isboolean(T0, T1)(auto ref T0 L, auto ref T1 n)
378 {
379     return lua_type(L, n) == LUA_TBOOLEAN;
380 }
381 
382 extern (D) auto lua_isthread(T0, T1)(auto ref T0 L, auto ref T1 n)
383 {
384     return lua_type(L, n) == LUA_TTHREAD;
385 }
386 
387 extern (D) auto lua_isnone(T0, T1)(auto ref T0 L, auto ref T1 n)
388 {
389     return lua_type(L, n) == LUA_TNONE;
390 }
391 
392 extern (D) auto lua_isnoneornil(T0, T1)(auto ref T0 L, auto ref T1 n)
393 {
394     return lua_type(L, n) <= 0;
395 }
396 
397 extern (D) auto lua_pushglobaltable(T)(auto ref T L)
398 {
399     return cast(void) lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS);
400 }
401 
402 extern (D) auto lua_tostring(T0, T1)(auto ref T0 L, auto ref T1 i)
403 {
404     return lua_tolstring(L, i, null);
405 }
406 
407 extern (D) auto lua_insert(T0, T1)(auto ref T0 L, auto ref T1 idx)
408 {
409     return lua_rotate(L, idx, 1);
410 }
411 
412 /* }============================================================== */
413 
414 /*
415 ** {==============================================================
416 ** compatibility macros for unsigned conversions
417 ** ===============================================================
418 */
419 
420 /* }============================================================== */
421 
422 /*
423 ** {======================================================================
424 ** Debug API
425 ** =======================================================================
426 */
427 
428 /*
429 ** Event codes
430 */
431 enum LUA_HOOKCALL = 0;
432 enum LUA_HOOKRET = 1;
433 enum LUA_HOOKLINE = 2;
434 enum LUA_HOOKCOUNT = 3;
435 enum LUA_HOOKTAILCALL = 4;
436 
437 /*
438 ** Event masks
439 */
440 enum LUA_MASKCALL = 1 << LUA_HOOKCALL;
441 enum LUA_MASKRET = 1 << LUA_HOOKRET;
442 enum LUA_MASKLINE = 1 << LUA_HOOKLINE;
443 enum LUA_MASKCOUNT = 1 << LUA_HOOKCOUNT; /* activation record */
444 
445 /* Functions to be called by the debugger in specific events */
446 alias lua_Hook = void function (lua_State* L, lua_Debug* ar);
447 
448 int lua_getstack (lua_State* L, int level, lua_Debug* ar);
449 int lua_getinfo (lua_State* L, const(char)* what, lua_Debug* ar);
450 const(char)* lua_getlocal (lua_State* L, const(lua_Debug)* ar, int n);
451 const(char)* lua_setlocal (lua_State* L, const(lua_Debug)* ar, int n);
452 const(char)* lua_getupvalue (lua_State* L, int funcindex, int n);
453 const(char)* lua_setupvalue (lua_State* L, int funcindex, int n);
454 
455 void* lua_upvalueid (lua_State* L, int fidx, int n);
456 void lua_upvaluejoin (lua_State* L, int fidx1, int n1, int fidx2, int n2);
457 
458 void lua_sethook (lua_State* L, lua_Hook func, int mask, int count);
459 lua_Hook lua_gethook (lua_State* L);
460 int lua_gethookmask (lua_State* L);
461 int lua_gethookcount (lua_State* L);
462 
463 struct lua_Debug
464 {
465     int event;
466     const(char)* name; /* (n) */
467     const(char)* namewhat; /* (n) 'global', 'local', 'field', 'method' */
468     const(char)* what; /* (S) 'Lua', 'C', 'main', 'tail' */
469     const(char)* source; /* (S) */
470     int currentline; /* (l) */
471     int linedefined; /* (S) */
472     int lastlinedefined; /* (S) */
473     ubyte nups; /* (u) number of upvalues */
474     ubyte nparams; /* (u) number of parameters */
475     char isvararg; /* (u) */
476     char istailcall; /* (t) */
477     char[LUA_IDSIZE] short_src; /* (S) */
478     /* private part */
479     struct CallInfo;
480     CallInfo* i_ci; /* active function */
481 }
482 
483 /* }====================================================================== */
484 
485 /******************************************************************************
486 * Copyright (C) 1994-2018 Lua.org, PUC-Rio.
487 *
488 * Permission is hereby granted, free of charge, to any person obtaining
489 * a copy of this software and associated documentation files (the
490 * "Software"), to deal in the Software without restriction, including
491 * without limitation the rights to use, copy, modify, merge, publish,
492 * distribute, sublicense, and/or sell copies of the Software, and to
493 * permit persons to whom the Software is furnished to do so, subject to
494 * the following conditions:
495 *
496 * The above copyright notice and this permission notice shall be
497 * included in all copies or substantial portions of the Software.
498 *
499 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
500 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
501 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
502 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
503 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
504 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
505 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
506 ******************************************************************************/
507