-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathluajit.pas
828 lines (672 loc) · 42.5 KB
/
luajit.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
{
This are the pascal headers for LuaJIT, based on
'luajit.h',
'lua.h',
'lualib.h' and
'lauxlib.h'.
LuaJIT commit: cb886b58176dc5cd969f512d1a633f06d7120941
Partially used the original FPC Headers by Lavergne Thomas and others.
}
{
Original license for LuaJIT:
}
{*
** LuaJIT -- a Just-In-Time Compiler for Lua. http://luajit.org/
**
** Copyright (C) 2005-2014 Mike Pall. All rights reserved.
**
** Permission is hereby granted, free of charge, to any person obtaining
** a copy of this software and associated documentation files (the
** 'Software'), to deal in the Software without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Software, and to
** permit persons to whom the Software is furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be
** included in all copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**
** [ MIT license: http://www.opensource.org/licenses/mit-license.php ]
*}
{
Original license for lua.h, lualib.h and lauxlib.h:
}
{******************************************************************************
* Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* 'Software'), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************}
unit luajit;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, unixtype;
const
{$IFDEF WINDOWS}
{$IFDEF WIN64}
LUAJIT_LibName = 'lua5.1-x64.dll';
{$ELSE}
LUAJIT_LibName = 'lua5.1.dll';
{$ENDIF}
{$ENDIF}
{$IFDEF UNIX}
{$IFDEF DARWIN}
LUAJIT_LibName = 'lua5.1.dylib';
{$ELSE}
LUAJIT_LibName = 'libluajit-5.1.so';
{$ENDIF}
{$ENDIF}
{$IFDEF MACOS}
SDLgfxLibName = 'lua5.1';
{$IFDEF FPC}
{$linklib lua5.1}
{$ENDIF}
{$ENDIF}
{ Lua }
const
TLUA_VERSION = 'Lua 5.1';
TLUA_RELEASE = 'Lua 5.1.4';
TLUA_VERSION_NUM = 501;
TLUA_COPYRIGHT = 'Copyright (C) 1994-2008 Lua.org, PUC-Rio';
TLUA_AUTHORS = 'R. Ierusalimschy, L. H. de Figueiredo & W. Celes';
{* mark for precompiled code (`<esc>Lua') *}
TLUA_SIGNATURE = '\033Lua';
{* option for multiple returns in `lua_pcall' and `lua_call' *}
TLUA_MULTRET = (-1);
{*
** pseudo-indices
*}
const
TLUA_REGISTRYINDEX = (-10000);
TLUA_ENVIRONINDEX = (-10001);
TLUA_GLOBALSINDEX = (-10002);
function lua_upvalueindex(i: Integer): Integer; inline;
const
{* thread status; 0 is OK *}
TLUA_YIELD = 1;
TLUA_ERRRUN = 2;
TLUA_ERRSYNTAX = 3;
TLUA_ERRMEM = 4;
TLUA_ERRERR = 5;
type
TLua_State = record
end;
PLua_State = ^TLua_State;
TLua_CFunction = function(L: Plua_State): Integer; cdecl;
PLua_CFunction = ^TLua_CFunction;
{*
** functions that read/write blocks when loading/dumping Lua chunks
*}
type
TLua_Reader = function(L: Plua_State; ud: Pointer; sz: Psize_t): PChar; cdecl;
TLua_Writer = function(L: Plua_State; const p: Pointer; sz: size_t; ud: Pointer): Integer; cdecl;
{*
** prototype for memory-allocation functions
*}
TLua_Alloc = function(ud, ptr: Pointer; osize, nsize: size_t): Pointer; cdecl;
{*
** basic types
*}
const
TLUA_TNONE = (-1);
TLUA_TNIL = 0;
TLUA_TBOOLEAN = 1;
TLUA_TLIGHTUSERDATA = 2;
TLUA_TNUMBER = 3;
TLUA_TSTRING = 4;
TLUA_TTABLE = 5;
TLUA_TFUNCTION = 6;
TLUA_TUSERDATA = 7;
TLUA_TTHREAD = 8;
{* minimum Lua stack available to a C function *}
TLUA_MINSTACK = 20;
type
{* Type of Numbers in Lua *}
TLua_Number = Double;
TLua_Integer = PtrInt;
{*
** state manipulation
*}
function lua_newstate(f: TLua_Alloc; ud: Pointer): Plua_state; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_newstate' {$ENDIF} {$ENDIF};
procedure lua_close(L: Plua_State); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_close' {$ENDIF} {$ENDIF};
function lua_newthread(L: Plua_State): Plua_State; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_newthread' {$ENDIF} {$ENDIF};
function lua_atpanic(L: Plua_State; panicf: TLua_CFunction): TLua_CFunction; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_atpanic' {$ENDIF} {$ENDIF};
{*
** basic stack manipulation
*}
function lua_gettop(L: Plua_State): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_gettop' {$ENDIF} {$ENDIF};
procedure lua_settop(L: Plua_State; idx: Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_settop' {$ENDIF} {$ENDIF};
procedure lua_pushvalue(L: Plua_State; Idx: Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_pushvalue' {$ENDIF} {$ENDIF};
procedure lua_remove(L: Plua_State; idx: Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_remove' {$ENDIF} {$ENDIF};
procedure lua_insert(L: Plua_State; idx: Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_insert' {$ENDIF} {$ENDIF};
procedure lua_replace(L: Plua_State; idx: Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_replace' {$ENDIF} {$ENDIF};
function lua_checkstack(L: Plua_State; sz: Integer): LongBool; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_checkstack' {$ENDIF} {$ENDIF};
procedure lua_xmove(from, to_: Plua_State; n: Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_xmove' {$ENDIF} {$ENDIF};
{*
** access functions (stack -> C)
*}
function lua_isnumber(L: Plua_State; idx: Integer): LongBool; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_isnumber' {$ENDIF} {$ENDIF};
function lua_isstring(L: Plua_State; idx: Integer): LongBool; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_isstring' {$ENDIF} {$ENDIF};
function lua_iscfunction(L: Plua_State; idx: Integer): LongBool; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_iscfunction' {$ENDIF} {$ENDIF};
function lua_isuserdata(L: Plua_State; idx: Integer): LongBool; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_isuserdata' {$ENDIF} {$ENDIF};
function lua_type(L: Plua_State; idx: Integer): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_type' {$ENDIF} {$ENDIF};
function lua_typename(L: Plua_State; tp: Integer): PChar; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_typename' {$ENDIF} {$ENDIF};
function lua_equal(L: Plua_State; idx1, idx2: Integer): LongBool; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_equal' {$ENDIF} {$ENDIF};
function lua_rawequal(L: Plua_State; idx1, idx2: Integer): LongBool; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_rawequal' {$ENDIF} {$ENDIF};
function lua_lessthan(L: Plua_State; idx1, idx2: Integer): LongBool; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_lessthan' {$ENDIF} {$ENDIF};
function lua_tonumber(L: Plua_State; idx: Integer): TLua_Number; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_tonumber' {$ENDIF} {$ENDIF};
function lua_tointeger(L: Plua_State; idx: Integer): TLua_Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_tointeger' {$ENDIF} {$ENDIF};
function lua_toboolean(L: Plua_State; idx: Integer): LongBool; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_toboolean' {$ENDIF} {$ENDIF};
function lua_tolstring(L: Plua_State; idx: Integer; len: Psize_t): PChar; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_tolstring' {$ENDIF} {$ENDIF};
function lua_objlen(L: Plua_State; idx: Integer): size_t; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_objlen' {$ENDIF} {$ENDIF};
function lua_tocfunction(L: Plua_State; idx: Integer): TLua_CFunction; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_tocfunction' {$ENDIF} {$ENDIF};
function lua_touserdata(L: Plua_State; idx: Integer): Pointer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_touserdata' {$ENDIF} {$ENDIF};
function lua_tothread(L: Plua_State; idx: Integer): Plua_State; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_tothread' {$ENDIF} {$ENDIF};
function lua_topointer(L: Plua_State; idx: Integer): Pointer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_topointer' {$ENDIF} {$ENDIF};
{*
** push functions (C -> stack)
*}
procedure lua_pushnil(L: Plua_State); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_pushnil' {$ENDIF} {$ENDIF};
procedure lua_pushnumber(L: Plua_State; n: TLua_Number); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_pushnumber' {$ENDIF} {$ENDIF};
procedure lua_pushinteger(L: Plua_State; n: TLua_Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_pushinteger' {$ENDIF} {$ENDIF};
procedure lua_pushlstring(L: Plua_State; const s: PChar; l_: size_t); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_pushlstring' {$ENDIF} {$ENDIF};
procedure lua_pushstring(L: Plua_State; const s: PChar); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_pushstring' {$ENDIF} {$ENDIF};
function lua_pushvfstring(L: Plua_State; const fmt: PChar; argp: Pointer): PChar; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_pushvfstring' {$ENDIF} {$ENDIF};
function lua_pushfstring(L: Plua_State; const fmt: PChar): PChar; cdecl; varargs; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_pushfstring' {$ENDIF} {$ENDIF};
procedure lua_pushcclosure(L: Plua_State; fn: TLua_CFunction; n: Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_pushcclosure' {$ENDIF} {$ENDIF};
procedure lua_pushboolean(L: Plua_State; b: LongBool); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_pushboolean' {$ENDIF} {$ENDIF};
procedure lua_pushlightuserdata(L: Plua_State; p: Pointer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_pushlightuserdata' {$ENDIF} {$ENDIF};
procedure lua_pushthread(L: Plua_State); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_pushthread' {$ENDIF} {$ENDIF};
{*
** get functions (Lua -> stack)
*}
procedure lua_gettable(L: Plua_State; idx: Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_gettable' {$ENDIF} {$ENDIF};
procedure lua_getfield(L: Plua_state; idx: Integer; k: PChar); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_getfield' {$ENDIF} {$ENDIF};
procedure lua_rawget(L: Plua_State; idx: Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_rawget' {$ENDIF} {$ENDIF};
procedure lua_rawgeti(L: Plua_State; idx, n: Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_rawgeti' {$ENDIF} {$ENDIF};
procedure lua_createtable(L: Plua_State; narr, nrec: Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_createtable' {$ENDIF} {$ENDIF};
function lua_newuserdata(L: Plua_State; sz: size_t): Pointer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_newuserdata' {$ENDIF} {$ENDIF};
function lua_getmetatable(L: Plua_State; objindex: Integer): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_getmetatable' {$ENDIF} {$ENDIF};
procedure lua_getfenv(L: Plua_State; idx: Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_getfenv' {$ENDIF} {$ENDIF};
{*
** set functions (stack -> Lua)
*}
procedure lua_settable(L: Plua_State; idx: Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_settable' {$ENDIF} {$ENDIF};
procedure lua_setfield(L: Plua_State; idx: Integer; const k: PChar); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_setfield' {$ENDIF} {$ENDIF};
procedure lua_rawset(L: Plua_State; idx: Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_rawset' {$ENDIF} {$ENDIF};
procedure lua_rawseti(L: Plua_State; idx, n: Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_rawseti' {$ENDIF} {$ENDIF};
function lua_setmetatable(L: Plua_State; objindex: Integer): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_setmetatable' {$ENDIF} {$ENDIF};
function lua_setfenv(L: Plua_State; idx: Integer): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_setfenv' {$ENDIF} {$ENDIF};
{*
** `load' and `call' functions (load and run Lua code)
*}
procedure lua_call(L: Plua_State; nargs, nresults: Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_call' {$ENDIF} {$ENDIF};
function lua_pcall(L: Plua_State; nargs, nresults, errf: Integer): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_pcall' {$ENDIF} {$ENDIF};
function lua_cpcall(L: Plua_State; func: TLua_CFunction; ud: Pointer): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_cpcall' {$ENDIF} {$ENDIF};
function lua_load(L: Plua_State; reader: TLua_Reader; dt: Pointer; const chunkname: PChar): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_load' {$ENDIF} {$ENDIF};
function lua_dump(L: Plua_State; writer: TLua_Writer; data: Pointer): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_dump' {$ENDIF} {$ENDIF};
{*
** coroutine functions
*}
function lua_yield(L: Plua_State; nresults: Integer): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_yield' {$ENDIF} {$ENDIF};
function lua_resume(L: Plua_State; narg: Integer): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_resume' {$ENDIF} {$ENDIF};
function lua_status(L: Plua_State): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_status' {$ENDIF} {$ENDIF};
{*
** garbage-collection function and options
*}
const
TLUA_GCSTOP = 0;
TLUA_GCRESTART = 1;
TLUA_GCCOLLECT = 2;
TLUA_GCCOUNT = 3;
TLUA_GCCOUNTB = 4;
TLUA_GCSTEP = 5;
TLUA_GCSETPAUSE = 6;
TLUA_GCSETSTEPMUL = 7;
function lua_gc(L: Plua_State; what, data: Integer): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_gc' {$ENDIF} {$ENDIF};
{*
** miscellaneous functions
*}
function lua_error(L: Plua_State): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_error' {$ENDIF} {$ENDIF};
function lua_next(L: Plua_State; idx: Integer): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_next' {$ENDIF} {$ENDIF};
procedure lua_concat(L: Plua_State; n: Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_concat' {$ENDIF} {$ENDIF};
function lua_getallocf(L: Plua_State; ud: PPointer): TLua_Alloc; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_getallocf' {$ENDIF} {$ENDIF};
procedure lua_setallocf(L: Plua_State; f: TLua_Alloc; ud: Pointer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_setallocf' {$ENDIF} {$ENDIF};
{*
** ===============================================================
** some useful macros
** ===============================================================
*}
procedure lua_pop(L: Plua_State; n: Integer); inline;
procedure lua_newtable(L: Plua_state); inline;
procedure lua_register(L: Plua_State; const n: PAnsiChar; f: TLua_CFunction); inline;
procedure lua_pushcfunction(L: Plua_State; f: TLua_CFunction); inline;
function lua_strlen(L: Plua_state; i: Integer): size_t; inline;
function lua_isfunction(L: Plua_State; n: Integer): Boolean; inline;
function lua_istable(L: Plua_State; n: Integer): Boolean; inline;
function lua_islightuserdata(L: Plua_State; n: Integer): Boolean; inline;
function lua_isnil(L: Plua_State; n: Integer): Boolean; inline;
function lua_isboolean(L: Plua_State; n: Integer): Boolean; inline;
function lua_isthread(L: Plua_State; n: Integer): Boolean; inline;
function lua_isnone(L: Plua_State; n: Integer): Boolean; inline;
function lua_isnoneornil(L: Plua_State; n: Integer): Boolean; inline;
procedure lua_pushliteral(L: Plua_State; s: PAnsiChar); inline;
procedure lua_setglobal(L: Plua_State; const s: PAnsiChar); inline;
procedure lua_getglobal(L: Plua_State; const s: PAnsiChar); inline;
function lua_tostring(L: Plua_State; i: Integer): PAnsiChar; inline;
{*
** compatibility macros and functions
*}
procedure lua_getregistry(L: Plua_State); inline;
function lua_getgccount(L: Plua_State): Integer; inline;
type
TLua_ChunkReader = TLua_Reader;
TLua_ChunkWriter = TLua_Writer;
{* hack *}
procedure lua_setlevel(from: Plua_state; to_: Plua_state); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_setlevel' {$ENDIF} {$ENDIF};
{*
** =======================================================================
** Debug API
** =======================================================================
*}
{*
** Event codes
*}
const
TLUA_HOOKCALL = 0;
TLUA_HOOKRET = 1;
TLUA_HOOKLINE = 2;
TLUA_HOOKCOUNT = 3;
TLUA_HOOKTAILRET = 4;
{*
** Event masks
*}
const
TLUA_MASKCALL = 1 shl Ord(TLUA_HOOKCALL);
TLUA_MASKRET = 1 shl Ord(TLUA_HOOKRET);
TLUA_MASKLINE = 1 shl Ord(TLUA_HOOKLINE);
TLUA_MASKCOUNT = 1 shl Ord(TLUA_HOOKCOUNT);
const
TLUA_IDSIZE = 60;
type
TLua_Debug = record {* activation record *}
event: Integer;
name: PAnsiChar; {* (n) *}
namewhat: PAnsiChar; {* (n) `global', `local', `field', `method' *}
what: PAnsiChar; {* (S) `Lua', `C', `main', `tail'*}
source: PAnsiChar; {* (S) *}
currentline: Integer; {* (l) *}
nups: Integer; {* (u) number of upvalues *}
linedefined: Integer; {* (S) *}
lastlinedefined: Integer; {* (S) *}
short_src: array[0..TLUA_IDSIZE - 1] of Char; {* (S) *}
{* private part *}
i_ci: Integer; {* active function *}
end;
PLua_Debug = ^TLua_Debug;
{* Functions to be called by the debuger in specific events *}
TLua_Hook = procedure(L: Plua_State; ar: Plua_Debug); cdecl;
function lua_getstack(L: Plua_State; level: Integer; ar: Plua_Debug): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_getstack' {$ENDIF} {$ENDIF};
function lua_getinfo(L: Plua_State; const what: PAnsiChar; ar: Plua_Debug): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_getinfo' {$ENDIF} {$ENDIF};
function lua_getlocal(L: Plua_State; const ar: Plua_Debug; n: Integer): PAnsiChar; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_getlocal' {$ENDIF} {$ENDIF};
function lua_setlocal(L: Plua_State; const ar: Plua_Debug; n: Integer): PAnsiChar; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_setlocal' {$ENDIF} {$ENDIF};
function lua_getupvalue(L: Plua_State; funcindex: Integer; n: Integer): PAnsiChar; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_getupvalue' {$ENDIF} {$ENDIF};
function lua_setupvalue(L: Plua_State; funcindex: Integer; n: Integer): PAnsiChar; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_setupvalue' {$ENDIF} {$ENDIF};
function lua_sethook(L: Plua_State; func: TLua_Hook; mask: Integer; count: Integer): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_sethook' {$ENDIF} {$ENDIF};
function lua_gethook(L: Plua_State): TLua_Hook; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_gethook' {$ENDIF} {$ENDIF};
function lua_gethookmask(L: Plua_State): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_gethookmask' {$ENDIF} {$ENDIF};
function lua_gethookcount(L: Plua_State): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_gethookcount' {$ENDIF} {$ENDIF};
{* From Lua 5.2. *}
function lua_upvalueid(L: Plua_State; idx: Integer; n: Integer): Pointer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_upvalueid' {$ENDIF} {$ENDIF};
procedure lua_upvaluejoin(L: Plua_State; idx1, n1, idx2, n2: Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_upvaluejoin' {$ENDIF} {$ENDIF};
function lua_loadx(L: Plua_State; reader: TLua_Reader; dt: Pointer; const chunkname: PAnsiChar; const mode: PAnsiChar): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_loadx' {$ENDIF} {$ENDIF};
{ lauxlib }
// functions added for Pascal
procedure lua_pushstring(L: Plua_State; const s: String);
// compatibilty macros
function luaL_getn(L: Plua_State; n: Integer): Integer; // calls lua_objlen
procedure luaL_setn(L: Plua_State; t, n: Integer); // does nothing!
{* extra error code for `luaL_load' *}
const
TLUA_ERRFILE = (TLUA_ERRERR+1);
type
TluaL_reg = record
name: PAnsiChar;
func: TLua_CFunction;
end;
PluaL_reg = ^TluaL_reg;
procedure luaL_openlib(L: Plua_State; const libname: PAnsiChar; const lr: PluaL_reg; nup: Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_openload' {$ENDIF} {$ENDIF};
procedure luaL_register(L: Plua_State; const libname: PAnsiChar; const lr: PluaL_reg); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_register' {$ENDIF} {$ENDIF};
function luaL_getmetafield(L: Plua_State; obj: Integer; const e: PAnsiChar): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_getmetafield' {$ENDIF} {$ENDIF};
function luaL_callmeta(L: Plua_State; obj: Integer; const e: PAnsiChar): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_callmeta' {$ENDIF} {$ENDIF};
function luaL_typerror(L: Plua_State; narg: Integer; const tname: PAnsiChar): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_typeerror' {$ENDIF} {$ENDIF};
function luaL_argerror(L: Plua_State; numarg: Integer; const extramsg: PAnsiChar): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_argerror' {$ENDIF} {$ENDIF};
function luaL_checklstring(L: Plua_State; numArg: Integer; l_: Psize_t): PAnsiChar; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_checklstring' {$ENDIF} {$ENDIF};
function luaL_optlstring(L: Plua_State; numArg: Integer; const def: PAnsiChar; l_: Psize_t): PAnsiChar; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_optlstring' {$ENDIF} {$ENDIF};
function luaL_checknumber(L: Plua_State; numArg: Integer): TLua_Number; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_checknumber' {$ENDIF} {$ENDIF};
function luaL_optnumber(L: Plua_State; nArg: Integer; def: TLua_Number): TLua_Number; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_optnumber' {$ENDIF} {$ENDIF};
function luaL_checkinteger(L: Plua_State; numArg: Integer): TLua_Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_checkinteger' {$ENDIF} {$ENDIF};
function luaL_optinteger(L: Plua_State; nArg: Integer; def: TLua_Integer): TLua_Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_optinteger' {$ENDIF} {$ENDIF};
procedure luaL_checkstack(L: Plua_State; sz: Integer; const msg: PAnsiChar); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_checkstack' {$ENDIF} {$ENDIF};
procedure luaL_checktype(L: Plua_State; narg, t: Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_checkstack' {$ENDIF} {$ENDIF};
procedure luaL_checkany(L: Plua_State; narg: Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_checkany' {$ENDIF} {$ENDIF};
function luaL_newmetatable(L: Plua_State; const tname: PAnsiChar): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_newmetatable' {$ENDIF} {$ENDIF};
function luaL_checkudata(L: Plua_State; ud: Integer; const tname: PAnsiChar): Pointer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_checkudata' {$ENDIF} {$ENDIF};
procedure luaL_where(L: Plua_State; lvl: Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_where' {$ENDIF} {$ENDIF};
{$IFNDEF DELPHI}
function luaL_error(L: Plua_State; const fmt: PAnsiChar; args: array of const): Integer; cdecl; external LUAJIT_LIBNAME; // note: C's ... to array of const conversion is not portable to Delphi
{$ENDIF}
function luaL_checkoption(L: Plua_State; narg: Integer; def: PAnsiChar; lst: PPAnsiChar): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_checkoption' {$ENDIF} {$ENDIF};
function luaL_ref(L: Plua_State; t: Integer): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_ref' {$ENDIF} {$ENDIF};
procedure luaL_unref(L: Plua_State; t, ref: Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_unref' {$ENDIF} {$ENDIF};
function luaL_loadfile(L: Plua_State; const filename: PAnsiChar): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_loadfile' {$ENDIF} {$ENDIF};
function luaL_loadbuffer(L: Plua_State; const buff: PAnsiChar; size: size_t; const name: PAnsiChar): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_loadbuffer' {$ENDIF} {$ENDIF};
function luaL_loadstring(L: Plua_State; const s: PAnsiChar): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_loadstring' {$ENDIF} {$ENDIF};
function luaL_newstate: Plua_State; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_newstate' {$ENDIF} {$ENDIF};
function lua_open: Plua_State; // compatibility; moved from unit lua to lauxlib because it needs luaL_newstate
function luaL_gsub(L: Plua_State; const s, p, r: PAnsiChar): PAnsiChar; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_gsub' {$ENDIF} {$ENDIF};
function luaL_findtable(L: Plua_State; idx: Integer; const fname: PAnsiChar; szhint: Integer): PAnsiChar; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_findtable' {$ENDIF} {$ENDIF};
{* From Lua 5.2. *}
function luaL_fileresult(L: Plua_State; stat: Integer; const fname: PAnsiChar): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_fileresult' {$ENDIF} {$ENDIF};
function luaL_execresult(L: Plua_State; state: Integer): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_execresult' {$ENDIF} {$ENDIF};
function luaL_loadfilex(L: Plua_State; const filename: PAnsiChar; const mode: PAnsiChar): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_loadfilex' {$ENDIF} {$ENDIF};
function luaL_loadbufferx(L: Plua_State; const buff: PAnsiChar; sz: size_t; const name: PAnsiChar; const mode: PAnsiChar): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_loadbufferx' {$ENDIF} {$ENDIF};
procedure luaL_traceback(L, L1: Plua_State; const msg: PAnsiChar; level: Integer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_traceback' {$ENDIF} {$ENDIF};
{*
** ===============================================================
** some useful macros
** ===============================================================
*}
procedure luaL_argcheck(L: Plua_State; cond: Boolean; numarg: Integer; extramsg: PAnsiChar); inline;
function luaL_checkstring(L: Plua_State; n: Integer): PAnsiChar; inline;
function luaL_optstring(L: Plua_State; n: Integer; d: PAnsiChar): PAnsiChar; inline;
function luaL_checkint(L: Plua_State; n: Integer): Integer; inline;
function luaL_checklong(L: Plua_State; n: Integer): LongInt; inline;
function luaL_optint(L: Plua_State; n: Integer; d: Double): Integer; inline;
function luaL_optlong(L: Plua_State; n: Integer; d: Double): LongInt; inline;
function luaL_typename(L: Plua_State; i: Integer): PAnsiChar; inline;
function lua_dofile(L: Plua_State; const filename: PAnsiChar): Integer; inline;
function lua_dostring(L: Plua_State; const str: PAnsiChar): Integer; inline;
procedure lua_Lgetmetatable(L: Plua_State; tname: PAnsiChar); inline;
//luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
{*
** =======================================================
** Generic Buffer manipulation
** =======================================================
*}
const
// note: this is just arbitrary, as it related to the BUFSIZ defined in stdio.h ...
TLUAL_BUFFERSIZE = 4096;
type
luaL_Buffer = record
p: PAnsiChar; (* current position in buffer *)
lvl: Integer; (* number of strings in the stack (level) *)
L: Plua_State;
buffer: array [0..TLUAL_BUFFERSIZE - 1] of Char; // warning: see note above about LUAL_BUFFERSIZE
end;
PluaL_Buffer = ^luaL_Buffer;
procedure luaL_addchar(B: PluaL_Buffer; c: Char); inline; // warning: see note above about LUAL_BUFFERSIZE
(* compatibility only (alias for luaL_addchar) *)
procedure luaL_putchar(B: PluaL_Buffer; c: Char); inline; // warning: see note above about LUAL_BUFFERSIZE
procedure luaL_addsize(B: PluaL_Buffer; n: Integer); inline;
procedure luaL_buffinit(L: Plua_State; B: PluaL_Buffer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_buffinit' {$ENDIF} {$ENDIF};
function luaL_prepbuffer(B: PluaL_Buffer): PAnsiChar; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_prepbuffer' {$ENDIF} {$ENDIF};
procedure luaL_addlstring(B: PluaL_Buffer; const s: PAnsiChar; l: size_t); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_addlstring' {$ENDIF} {$ENDIF};
procedure luaL_addstring(B: PluaL_Buffer; const s: PAnsiChar); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_addstring' {$ENDIF} {$ENDIF};
procedure luaL_addvalue(B: PluaL_Buffer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_addvalue' {$ENDIF} {$ENDIF};
procedure luaL_pushresult(B: PluaL_Buffer); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_pushresult' {$ENDIF} {$ENDIF};
{* compatibility with ref system *}
{* pre-defined references *}
const
LUA_NOREF = -2;
LUA_REFNIL = -1;
{lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \
(lua_pushstring(L, 'unlocked references are obsolete'), lua_error(L), 0))}
procedure lua_unref(L: Plua_State; ref: Integer); inline;
procedure lua_getref(L: Plua_State; ref: Integer); inline;
{ LuaLib }
const
LUA_FILEHANDLE = 'FILE*';
LUA_COLIBNAME = 'coroutine';
LUA_TABLIBNAME = 'table';
LUA_IOLIBNAME = 'io';
LUA_OSLIBNAME = 'os';
LUA_STRLINAME = 'string';
LUA_MATHLIBNAME = 'math';
LUA_DBLIBNAME = 'debug';
LUA_LOADLIBNAME = 'package';
function luaopen_base(L: Plua_State): LongBool; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_openbase' {$ENDIF} {$ENDIF};
function luaopen_math(L: Plua_State): LongBool; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_openmath' {$ENDIF} {$ENDIF};
function luaopen_string(L: Plua_State): LongBool; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_openstring' {$ENDIF} {$ENDIF};
function luaopen_table(L: Plua_State): LongBool; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_opentable' {$ENDIF} {$ENDIF};
function luaopen_io(L: Plua_State): LongBool; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_openio' {$ENDIF} {$ENDIF};
function luaopen_os(L: Plua_State): LongBool; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_openos' {$ENDIF} {$ENDIF};
function luaopen_package(L: Plua_State): LongBool; cdecl;external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_openpackage' {$ENDIF} {$ENDIF};
function luaopen_debug(L: Plua_State): LongBool; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_opendebug' {$ENDIF} {$ENDIF};
function luaopen_bit(L: Plua_State): LongBool; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_openbit' {$ENDIF} {$ENDIF};
function luaopen_jit(L: Plua_State): LongBool; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_openjit' {$ENDIF} {$ENDIF};
function luaopen_ffi(L: Plua_State): LongBool; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_lua_openffi' {$ENDIF} {$ENDIF};
procedure luaL_openlibs(L: Plua_State); cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaL_openlibs' {$ENDIF} {$ENDIF};
{ LuaJIT }
const
LUAJIT_VERSION = 'LuaJIT 2.0.3';
LUAJIT_VERSION_NUM = 20003; {* Version 2.0.3 = 02.00.03. *}
//LUAJIT_VERSION_SYM = luaJIT_version_2_0_3
LUAJIT_COPYRIGHT = 'Copyright (C) 2005-2014 Mike Pall';
LUAJIT_URL = 'http://luajit.org/';
{* Modes for luaJIT_setmode. *}
TLUAJIT_MODE_MASK = $00ff;
const
TLUAJIT_MODE_ENGINE = 0; {* Set mode for whole JIT engine. *}
TLUAJIT_MODE_DEBUG = 1; {* Set debug mode (idx = level). *}
TLUAJIT_MODE_FUNC = 2; {* Change mode for a function. *}
TLUAJIT_MODE_ALLFUNC = 3; {* Recurse into subroutine protos. *}
TLUAJIT_MODE_ALLSUBFUNC = 4; {* Change only the subroutines. *}
TLUAJIT_MODE_TRACE = 5; {* Flush a compiled trace. *}
TLUAJIT_MODE_WRAPCFUNC = $10; {* Set wrapper mode for C function calls. *}
const
{* Flags or'ed in to the mode. *}
TLUAJIT_MODE_OFF = $0000; {* Turn feature off. *}
TLUAJIT_MODE_ON = $0100; {* Turn feature on. *}
TLUAJIT_MODE_FLUSH = $0200; {* Flush JIT-compiled code. *}
{* LuaJIT public C API. *}
{* Control the JIT engine. *}
function luaJIT_setmode(L: PLua_State; idx: Integer; mode: Integer): Integer; cdecl; external LUAJIT_LIBNAME {$IFDEF DELPHI} {$IFDEF MACOS} name '_luaJIT_setmode' {$ENDIF} {$ENDIF};
{* Enforce (dynamic) linker error for version mismatches. Call from main. *}
//procedure LUAJIT_VERSION_SYM();
implementation
function lua_upvalueindex(i: Integer): Integer;
begin
Result := TLUA_GLOBALSINDEX - i;
end;
procedure lua_pop(L: Plua_State; n: Integer);
begin
lua_settop(L, -n - 1);
end;
procedure lua_newtable(L: Plua_State);
begin
lua_createtable(L, 0, 0);
end;
procedure lua_register(L: Plua_State; const n: PAnsiChar; f: TLua_CFunction);
begin
lua_pushcfunction(L, f);
lua_setglobal(L, n);
end;
procedure lua_pushcfunction(L: Plua_State; f: TLua_CFunction);
begin
lua_pushcclosure(L, f, 0);
end;
function lua_strlen(L: Plua_State; i: Integer): size_t;
begin
Result := lua_objlen(L, i);
end;
function lua_isfunction(L: Plua_State; n: Integer): Boolean;
begin
Result := lua_type(L, n) = TLUA_TFUNCTION;
end;
function lua_istable(L: Plua_State; n: Integer): Boolean;
begin
Result := lua_type(L, n) = TLUA_TTABLE;
end;
function lua_islightuserdata(L: Plua_State; n: Integer): Boolean;
begin
Result := lua_type(L, n) = TLUA_TLIGHTUSERDATA;
end;
function lua_isnil(L: Plua_State; n: Integer): Boolean;
begin
Result := lua_type(L, n) = TLUA_TNIL;
end;
function lua_isboolean(L: Plua_State; n: Integer): Boolean;
begin
Result := lua_type(L, n) = TLUA_TBOOLEAN;
end;
function lua_isthread(L: Plua_State; n: Integer): Boolean;
begin
Result := lua_type(L, n) = TLUA_TTHREAD;
end;
function lua_isnone(L: Plua_State; n: Integer): Boolean;
begin
Result := lua_type(L, n) = TLUA_TNONE;
end;
function lua_isnoneornil(L: Plua_State; n: Integer): Boolean;
begin
Result := lua_type(L, n) <= 0;
end;
procedure lua_pushliteral(L: Plua_State; s: PAnsiChar);
begin
lua_pushlstring(L, s, Length(s));
end;
procedure lua_setglobal(L: Plua_State; const s: PAnsiChar);
begin
lua_setfield(L, TLUA_GLOBALSINDEX, s);
end;
procedure lua_getglobal(L: Plua_State; const s: PAnsiChar);
begin
lua_getfield(L, TLUA_GLOBALSINDEX, s);
end;
function lua_tostring(L: Plua_State; i: Integer): PAnsiChar;
begin
Result := lua_tolstring(L, i, nil);
end;
procedure lua_getregistry(L: Plua_State);
begin
lua_pushvalue(L, TLUA_REGISTRYINDEX);
end;
function lua_getgccount(L: Plua_State): Integer;
begin
Result := lua_gc(L, TLUA_GCCOUNT, 0);
end;
procedure lua_pushstring(L: Plua_State; const s: string);
begin
lua_pushlstring(L, PAnsiChar(s), Length(s));
end;
function luaL_getn(L: Plua_State; n: Integer): Integer;
begin
Result := lua_objlen(L, n);
end;
procedure luaL_setn(L: Plua_State; t, n: Integer);
begin
// does nothing as this operation is deprecated
end;
function lua_open: Plua_State;
begin
Result := luaL_newstate;
end;
procedure luaL_argcheck(L: Plua_State; cond: Boolean; numarg: Integer; extramsg: PAnsiChar);
begin
if not cond then
luaL_argerror(L, numarg, extramsg)
end;
function luaL_checkstring(L: Plua_State; n: Integer): PAnsiChar;
begin
Result := luaL_checklstring(L, n, nil)
end;
function luaL_optstring(L: Plua_State; n: Integer; d: PAnsiChar): PAnsiChar;
begin
Result := luaL_optlstring(L, n, d, nil)
end;
function luaL_checkint(L: Plua_State; n: Integer): Integer;
begin
Result := Integer(Trunc(luaL_checknumber(L, n)))
end;
function luaL_checklong(L: Plua_State; n: Integer): LongInt;
begin
Result := LongInt(Trunc(luaL_checknumber(L, n)))
end;
function luaL_optint(L: Plua_State; n: Integer; d: Double): Integer;
begin
Result := Integer(Trunc(luaL_optnumber(L, n, d)))
end;
function luaL_optlong(L: Plua_State; n: Integer; d: Double): LongInt;
begin
Result := LongInt(Trunc(luaL_optnumber(L, n, d)))
end;
function luaL_typename(L: Plua_State; i: Integer): PAnsiChar;
begin
Result := lua_typename(L, lua_type(L, i));
end;
function lua_dofile(L: Plua_State; const filename: PAnsiChar): Integer;
begin
Result := luaL_loadfile(L, filename);
if Result = 0 then
Result := lua_pcall(L, 0, TLUA_MULTRET, 0);
end;
function lua_dostring(L: Plua_State; const str: PAnsiChar): Integer;
begin
Result := luaL_loadstring(L, str);
if Result = 0 then
Result := lua_pcall(L, 0, TLUA_MULTRET, 0);
end;
procedure lua_Lgetmetatable(L: Plua_State; tname: PAnsiChar);
begin
lua_getfield(L, TLUA_REGISTRYINDEX, tname);
end;
procedure luaL_addchar(B: PluaL_Buffer; c: Char);
begin
if Cardinal(@(B^.p)) < (Cardinal(@(B^.buffer[0])) + TLUAL_BUFFERSIZE) then
luaL_prepbuffer(B);
B^.p[1] := c;
B^.p := B^.p + 1;
end;
procedure luaL_putchar(B: PluaL_Buffer; c: Char);
begin
luaL_addchar(B, c);
end;
procedure luaL_addsize(B: PluaL_Buffer; n: Integer);
begin
B^.p := B^.p + n;
end;
procedure lua_unref(L: Plua_State; ref: Integer);
begin
luaL_unref(L, TLUA_REGISTRYINDEX, ref);
end;
procedure lua_getref(L: Plua_State; ref: Integer);
begin
lua_rawgeti(L, TLUA_REGISTRYINDEX, ref);
end;
end.