-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlua.au3
1554 lines (1318 loc) · 61.5 KB
/
lua.au3
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
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include-once
#cs
LUA programming language wrapper for AutoIt3.
Developped for lua v5.3.
Nearly all lua C API functions are wrapped, with exception to functions that can raise an error because lua
uses C's setjmp/longjmp, and it seems that it is not supported by AutoIt (or am I missing something...).
Some C functions that are useless for AutoIt are not wrapped (see comments), and sometimes, 2 functions are
wrapped in only one AutoIt function with optional parameters.
There are some specific AutoIt functions:
_lua_ExtractDll, _lua_Startup, _lua_Terminate, _au3Lua_pushAny, _au3Lua_readAny, _au3Lua_dumpStack
Also, remember that lua C API is quite low level, so any error in stack indexes for example will result in
script crash without any error message!
#ce
; #VARIABLES# =========================================================================================================
Global $__gLua_hDLL = -1
; =====================================================================================================================
; #CONSTANTS# =========================================================================================================
; HEADER: lua.h
Const $LUA_VERSION_MAJOR = 5
Const $LUA_VERSION_MINOR = 3
Const $LUA_VERSION_NUM = 503 ; this is used by _luaL_checkversion to check if this UDF and DLLs versions are the same
; so, if you want to use a DLL of different version, you must change this constant
; and also the implementation of AutoIt wrappers if needed
Const $LUA_VERSION_RELEASE = 5
Const $LUA_VERSION = "Lua " & $LUA_VERSION_MAJOR & "." & $LUA_VERSION_MINOR
Const $LUA_RELEASE = $LUA_VERSION & "." & $LUA_VERSION_RELEASE
Const $LUA_COPYRIGHT = $LUA_RELEASE & " Copyright (C) 1994-2018 Lua.org, PUC-Rio"
Const $LUA_AUTHORS = "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
; mark for precompiled code ('<esc>Lua')
Const $LUA_SIGNATURE = Binary("0x1b") & StringToBinary("Lua")
; option for multiple returns in 'lua_pcall' and 'lua_call'
Const $LUA_MULTRET = -1
; Pseudo-indices
; (-LUAI_MAXSTACK is the minimum valid index; we keep some free empty space after that to help overflow detection)
Const $LUA_REGISTRYINDEX = -1000000 - 1000 ; LUAI_MAXSTACK = 1000000 because on Windows LUAI_BITSINT >= 32
Func _lua_upvalueIndex($i)
Return $LUA_REGISTRYINDEX - $i
EndFunc ;==>_lua_upvalueIndex
; thread status
Const $LUA_OK = 0
Const $LUA_YIELD = 1
Const $LUA_ERRRUN = 2
Const $LUA_ERRSYNTAX = 3
Const $LUA_ERRMEM = 4
Const $LUA_ERRGCMM = 5
Const $LUA_ERRERR = 6
; basic types
Const $LUA_TNONE = -1
Const $LUA_TNIL = 0
Const $LUA_TBOOLEAN = 1
Const $LUA_TLIGHTUSERDATA = 2
Const $LUA_TNUMBER = 3
Const $LUA_TSTRING = 4
Const $LUA_TTABLE = 5
Const $LUA_TFUNCTION = 6
Const $LUA_TUSERDATA = 7
Const $LUA_TTHREAD = 8
Const $LUA_NUMTAGS = 9
; minimum Lua stack available to a C function
Const $LUA_MINSTACK = 20
; predefined values in the registry
Const $LUA_RIDX_MAINTHREAD = 1
Const $LUA_RIDX_GLOBALS = 2
Const $LUA_RIDX_LAST = $LUA_RIDX_GLOBALS
Const $LUA_OPADD = 0 ; ORDER TM, ORDER OP
Const $LUA_OPSUB = 1
Const $LUA_OPMUL = 2
Const $LUA_OPMOD = 3
Const $LUA_OPPOW = 4
Const $LUA_OPDIV = 5
Const $LUA_OPIDIV = 6
Const $LUA_OPBAND = 7
Const $LUA_OPBOR = 8
Const $LUA_OPBXOR = 9
Const $LUA_OPSHL = 10
Const $LUA_OPSHR = 11
Const $LUA_OPUNM = 12
Const $LUA_OPBNOT = 13
Const $LUA_OPEQ = 0
Const $LUA_OPLT = 1
Const $LUA_OPLE = 2
; Garbage collection function and options
Const $LUA_GCSTOP = 0
Const $LUA_GCRESTART = 1
Const $LUA_GCCOLLECT = 2
Const $LUA_GCCOUNT = 3
Const $LUA_GCCOUNTB = 4
Const $LUA_GCSTEP = 5
Const $LUA_GCSETPAUSE = 6
Const $LUA_GCSETSTEPMUL = 7
Const $LUA_GCISRUNNING = 9
; -----------------
; HEADER: lauxlib.h
; -----------------
; extra error code for 'luaL_loadfilex'
Const $LUA_ERRFILE = $LUA_ERRERR + 1
; key, in the registry, for table of loaded modules
Const $LUA_LOADED_TABLE = "_LOADED"
; key, in the registry, for table of preloaded loaders
Const $LUA_PRELOAD_TABLE = "_PRELOAD"
;~ Const $LUAL_NUMSIZES = 8*16 + 8 ; (sizeof(lua_Integer)*16 + sizeof(lua_Number))
; predefined references
Const $LUA_NOREF = -2
Const $LUA_REFNIL = -1
; standard library names
Const $LUA_COLIBNAME = "coroutine"
Const $LUA_TABLIBNAME = "table"
Const $LUA_IOLIBNAME = "io"
Const $LUA_OSLIBNAME = "os"
Const $LUA_STRLIBNAME = "string"
Const $LUA_UTF8LIBNAME = "utf8"
Const $LUA_BITLIBNAME = "bit32"
Const $LUA_MATHLIBNAME = "math"
Const $LUA_DBLIBNAME = "debug"
Const $LUA_LOADLIBNAME = "package"
; =====================================================================================================================
; =====================================================================================================================
; AutoIt specific helper functions
; =====================================================================================================================
; This function will extract either lua53_x86.dll or lua53_x64.dll according to @AutoItX64 and return DLLs full path,
; that can then be used as an argument to _lua_Startup.
; Note that this function will work only if lua_dlls.au3 is included to the script.
; On error, or if lua_dlls.au3 is not included, empty string "" is returned (which is default parameter to _lua_Startup)
;
; Extract lua dll to $sFolder, returning the full path of the extracted dll (can be used as parameter to _lua_Startup)
Func _lua_ExtractDll($sFolder = @ScriptDir)
$sFolder = $sFolder & "\lua53_" & (@AutoItX64 ? "x64" : "x86") & ".dll"
Local $vRet = Call("__lua_binFile_lua53_" & (@AutoItX64 ? "x64" : "x86") & "_dll", $sFolder)
If Not $vRet Or (@error = 0xDEAD And @extended = 0xBEEF) Then Return ""
Return $sFolder
EndFunc
; Open lua dll
Func _lua_Startup($sDllPath = "")
If $__gLua_hDLL == -1 Then
If Not $sDllPath Then
$sDllPath = @AutoItX64 ? "lua53_x64.dll" : "lua53_x86.dll"
EndIf
$__gLua_hDLL = DllOpen($sDllPath)
If $__gLua_hDLL == -1 Then Exit 0 * MsgBox(16, "Fatal Error", "Unable to load '" & $sDllPath & "'") - 1
EndIf
Return 1
EndFunc ;==>_lua_Startup
; Close lua dll
Func _lua_Shutdown()
If $__gLua_hDLL <> -1 Then
DllClose($__gLua_hDLL)
$__gLua_hDLL = -1
EndIf
Return 1
EndFunc ;==>_lua_Terminate
; This function will read the lua value in stack index $iIdx and return it as AutoIt value
; values are converted to appropriate AutoIt value type:
; - nil/none => Null
; - boolean => Boolean
; - integer => Integer
; - number => Double
; - string => either Binary or String (according to $bStringAsBinary)
; - thread, userdata, lightuserdata, function => Pointer
; - table => Array (if metafield __au3array found) or Scripting.Dictionary
;
; Read the lua value at index $iIdx, and convert it to AutoIt value
Func _au3Lua_readAny($pState, $iIdx, $bStringAsBinary = True)
$iIdx = _lua_absIndex($pState, $iIdx)
Switch _lua_type($pState, $iIdx)
Case $LUA_TNIL, $LUA_TNONE
Return Null
Case $LUA_TBOOLEAN
Return _lua_toBoolean($pState, $iIdx)
Case $LUA_TNUMBER
If _lua_isInteger($pState, $iIdx) Then
Return _lua_toInteger($pState, $iIdx)
Else
Return _lua_toNumber($pState, $iIdx)
EndIf
Case $LUA_TSTRING ; lua strings are read as binary data (use BinaryToString to convert to actual string)
Return $bStringAsBinary ? _lua_toBinary($pState, $iIdx) : _lua_toString($pState, $iIdx)
Case $LUA_TTHREAD
Return _lua_toThread($pState, $iIdx)
Case $LUA_TFUNCTION
Return _lua_toCFunction($pState, $iIdx)
Case $LUA_TUSERDATA, $LUA_TLIGHTUSERDATA
Return _lua_toUserdata($pState, $iIdx)
Case $LUA_TTABLE
If _luaL_getMetaField($pState, $iIdx, "__au3array") = $LUA_TNIL Then
; Object by default
_lua_pushNil($pState)
Local $oRet = ObjCreate("Scripting.Dictionary")
While _lua_next($pState, $iIdx)
$oRet.Item(_au3Lua_readAny($pState, -2, False)) = _au3Lua_readAny($pState, -1, $bStringAsBinary)
_lua_pop($pState, 1)
WEnd
_lua_pop($pState, 1)
Return $oRet
Else
_lua_pop($pState, 1) ; pop metafield __au3array
; if __au3array exists in object's metatable
_lua_len($pState, $iIdx)
Local $aRet[_lua_toInteger($pState, -1)]
_lua_pop($pState, 1)
For $i = 1 To UBound($aRet)
_lua_rawGetI($pState, $iIdx, $i)
$aRet[$i - 1] = _au3Lua_readAny($pState, -1, $bStringAsBinary)
_lua_pop($pState, 1)
Next
Return $aRet
EndIf
EndSwitch
EndFunc ;==>_au3Lua_readAny
; This function will push any AutoIt value to $pState lua stack
; values are converted to the appropriate lua type, with nested types supported (arrays in tables...):
; - Keyword/Null => nil
; - Boolean => boolean
; - Integers => integer
; - Floats/Doubles => number
; - String => string (converted to UTF8)
; - Binary => string (as is)
; - Array => table[1 .. n] with metafield __au3array = true
; - Scription.Dictionary => table[keys] = values
; - UserFunction => cfunction
;
; Pushes any AutoIt value to lua stack, converting it to the appropriate lua type (with nested types supported (arrays in tables...))
Func _au3Lua_pushAny($pState, $vValue)
Switch VarGetType($vValue)
Case "Keyword"
_lua_pushNil($pState)
Case "Int32", "Int64"
_lua_pushInteger($pState, $vValue)
Case "Double"
_lua_pushNumber($pState, $vValue)
Case "String"
_lua_pushString($pState, $vValue)
Case "Binary"
_lua_pushBinary($pState, $vValue)
Case "Bool"
_lua_pushBoolean($pState, $vValue)
Case "Array"
If UBound($vValue, 0) = 1 Then
_lua_createTable($pState, UBound($vValue), 0)
For $i = 0 To UBound($vValue) - 1
_au3Lua_pushAny($pState, $vValue[$i])
_lua_rawSetI($pState, -2, $i + 1)
Next
; set metatable to mark as Array
_lua_newTable($pState)
_lua_pushString($pState, "__au3array")
_lua_pushBoolean($pState, True)
_lua_setTable($pState, -3)
_lua_setMetatable($pState, -2)
Else
Return SetError(1, 0, False) ; unsupported multi-dimensional arrays
EndIf
Case "Object"
If ObjName($vValue, 2) = "Scripting.Dictionary" Then
_lua_createTable($pState, 0, $vValue.Count)
For $vKey In $vValue.Keys()
_au3Lua_pushAny($pState, $vKey)
_au3Lua_pushAny($pState, $vValue.Item($vKey))
_lua_rawSet($pState, -3)
Next
Else
Return SetError(1, 0, False) ; unsupported object
EndIf
Case "Function"
Return SetError(1, 0, False) ; cannot push AutoIt functions
Case "UserFunction"
_lua_pushCFunction($pState, $vValue)
EndSwitch
Return True
EndFunc ;==>_au3Lua_pushAny
Func _au3Lua_dumpStack($pState, $pfnCallback = ConsoleWrite)
$pfnCallback("> Stack: ")
For $i = 1 To _lua_getTop($pState)
Switch _lua_type($pState, $i)
Case $LUA_TNIL
$pfnCallback("nil ")
Case $LUA_TBOOLEAN, $LUA_TNUMBER
$pfnCallback(_au3Lua_readAny($pState, $i) & " ")
Case $LUA_TSTRING
$pfnCallback('"' & _au3Lua_readAny($pState, $i) & '" ')
Case Else
$pfnCallback("'" & _lua_typeName($pState, _lua_type($pState, $i)) & "' ")
EndSwitch
Next
$pfnCallback(@CRLF)
EndFunc ;==>_au3Lua_dumpStack
; =====================================================================================================================
; HEADER: lua.h
; =====================================================================================================================
; ------------------
; State manipulation
; ------------------
;~ LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
Func _lua_newState($pfnAlloc, $pUserData = 0)
Local $aRet = DllCall($__gLua_hDLL, "ptr:cdecl", "lua_newstate", "ptr", __lua_helper_regFunc($pfnAlloc, "ptr:cdecl", "ptr;ptr;ulong_ptr;ulong_ptr"), "ptr", $pUserData)
If @error Then Return SetError(@error, 0, Null)
Return $aRet[0]
EndFunc ;==>_lua_newState
;~ LUA_API void (lua_close) (lua_State *L);
Func _lua_close($pState)
DllCall($__gLua_hDLL, "none:cdecl", "lua_close", "ptr", $pState)
EndFunc ;==>_lua_close
;~ LUA_API lua_State *(lua_newthread) (lua_State *L);
Func _lua_newThread($pState)
Local $aRet = DllCall($__gLua_hDLL, "ptr:cdecl", "_lua_newthread", "ptr", $pState)
If @error Then Return SetError(@error, 0, Null)
Return $aRet[0]
EndFunc ;==>_lua_newThread
;~ LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
Func _lua_atPanic($pState, $pfnAtPanic)
Local $aRet = DllCall($__gLua_hDLL, "ptr:cdecl", "lua_atpanic", "ptr", $pState, "ptr", __lua_helper_regFunc($pfnAtPanic, "int:cdecl", "ptr"))
If @error Then Return SetError(@error, 0, Null)
Return $aRet[0]
EndFunc ;==>_lua_atPanic
;~ LUA_API const lua_Number *(lua_version) (lua_State *L);
Func _lua_version($pState = Null)
Local $aRet = DllCall($__gLua_hDLL, "ptr:cdecl", "lua_version", "ptr", $pState)
If @error Then Return SetError(@error, 0, 0)
Return DllStructGetData(DllStructCreate("double", $aRet[0]), 1)
EndFunc ;==>_lua_version
; ------------------------
; basic stack manipulation
; ------------------------
;~ LUA_API int (lua_absindex) (lua_State *L, int idx);
Func _lua_absIndex($pState, $iIdx)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_absindex", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, 0)
Return $aRet[0]
EndFunc ;==>_lua_absIndex
;~ LUA_API int (lua_gettop) (lua_State *L);
Func _lua_getTop($pState)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_gettop", "ptr", $pState)
If @error Then Return SetError(@error, 0, 0)
Return $aRet[0]
EndFunc ;==>_lua_getTop
;~ LUA_API void (lua_settop) (lua_State *L, int idx);
Func _lua_setTop($pState, $iIdx)
Local $aRet = DllCall($__gLua_hDLL, "none:cdecl", "lua_settop", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_setTop
;~ LUA_API void (lua_pushvalue) (lua_State *L, int idx);
Func _lua_pushValue($pState, $iIdx)
Local $aRet = DllCall($__gLua_hDLL, "none:cdecl", "lua_pushvalue", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_pushValue
;~ LUA_API void (lua_rotate) (lua_State *L, int idx, int n);
Func _lua_rotate($pState, $iIdx, $iN)
Local $aRet = DllCall($__gLua_hDLL, "none:cdecl", "lua_rotate", "ptr", $pState, "int", $iIdx, "int", $iN)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_rotate
;~ LUA_API void (lua_copy) (lua_State *L, int fromidx, int toidx);
Func _lua_copy($pState, $iFromIdx, $iToIdx)
Local $aRet = DllCall($__gLua_hDLL, "none:cdecl", "lua_copy", "ptr", $pState, "int", $iFromIdx, "int", $iToIdx)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_copy
;~ LUA_API int (lua_checkstack) (lua_State *L, int n);
Func _lua_checkStack($pState, $iN)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_checkstack", "ptr", $pState, "int", $iN)
If @error Then Return SetError(@error, 0, False)
Return $aRet[0] <> 0
EndFunc ;==>_lua_checkStack
;~ LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n);
Func _lua_xMove($pFromState, $pToState, $iN)
Local $aRet = DllCall($__gLua_hDLL, "none:cdecl", "lua_xmove", "ptr", $pFromState, "ptr", $pToState, "int", $iN)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_xMove
; -----------------------------
; Access functions (stack -> C)
; -----------------------------
;~ LUA_API int (lua_isnumber) (lua_State *L, int idx);
Func _lua_isNumber($pState, $iIdx)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_isnumber", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, False)
Return $aRet[0] <> 0
EndFunc ;==>_lua_isNumber
;~ LUA_API int (lua_isstring) (lua_State *L, int idx);
Func _lua_isString($pState, $iIdx)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_isstring", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, False)
Return $aRet[0] <> 0
EndFunc ;==>_lua_isString
;~ LUA_API int (lua_iscfunction) (lua_State *L, int idx);
Func _lua_isCFunction($pState, $iIdx)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_iscfunction", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, False)
Return $aRet[0] <> 0
EndFunc ;==>_lua_isCFunction
;~ LUA_API int (lua_isinteger) (lua_State *L, int idx);
Func _lua_isInteger($pState, $iIdx)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_isinteger", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, False)
Return $aRet[0] <> 0
EndFunc ;==>_lua_isInteger
;~ LUA_API int (lua_isuserdata) (lua_State *L, int idx);
Func _lua_isUserdata($pState, $iIdx)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_isuserdata", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, False)
Return $aRet[0] <> 0
EndFunc ;==>_lua_isUserdata
;~ LUA_API int (lua_type) (lua_State *L, int idx);
Func _lua_type($pState, $iIdx)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_type", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, $LUA_TNONE)
Return $aRet[0]
EndFunc ;==>_lua_type
;~ LUA_API const char *(lua_typename) (lua_State *L, int tp);
Func _lua_typeName($pState, $iType)
Local $aRet = DllCall($__gLua_hDLL, "str:cdecl", "lua_typename", "ptr", $pState, "int", $iType)
If @error Then Return SetError(@error, 0, "")
Return $aRet[0]
EndFunc ;==>_lua_typeName
;~ LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum);
Func _lua_toNumber($pState, $iIdx)
Local $aRet = DllCall($__gLua_hDLL, "double:cdecl", "lua_tonumberx", "ptr", $pState, "int", $iIdx, "int*", 0)
If @error Then Return SetError(@error, 0, 0)
Return SetError($aRet[3] = 0, 0, $aRet[0])
EndFunc ;==>_lua_toNumber
;~ LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum);
Func _lua_toInteger($pState, $iIdx)
Local $aRet = DllCall($__gLua_hDLL, "int64:cdecl", "lua_tointegerx", "ptr", $pState, "int", $iIdx, "int*", 0)
If @error Then Return SetError(@error, 0, 0)
Return SetError($aRet[3] = 0, 0, $aRet[0])
EndFunc ;==>_lua_toInteger
;~ LUA_API int (lua_toboolean) (lua_State *L, int idx);
Func _lua_toBoolean($pState, $iIdx)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_toboolean", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, 0)
Return $aRet[0] <> 0
EndFunc ;==>_lua_toBoolean
;~ LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len); TODO: test
Func _lua_toString($pState, $iIdx)
Local $vRet = _lua_toBinary($pState, $iIdx)
SetError(@error, @extended)
Return BinaryToString($vRet, 4)
EndFunc ;==>_lua_toString
Func _lua_toBinary($pState, $iIdx)
Local $aRet = DllCall($__gLua_hDLL, "ptr:cdecl", "lua_tolstring", "ptr", $pState, "int", $iIdx, "ulong_ptr*", 0)
If @error Then Return SetError(@error, 0, Binary(""))
Return __lua_helper_ptr2bin($aRet[0], $aRet[3])
EndFunc ;==>_lua_toBinary
;~ LUA_API size_t (lua_rawlen) (lua_State *L, int idx);
Func _lua_rawLen($pState, $iIdx)
Local $aRet = DllCall($__gLua_hDLL, "ulong_ptr:cdecl", "lua_rawlen", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, 0)
Return $aRet[0]
EndFunc ;==>_lua_rawLen
;~ LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx);
Func _lua_toCFunction($pState, $iIdx)
Local $aRet = DllCall($__gLua_hDLL, "ptr:cdecl", "lua_tocfunction", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, 0)
Return $aRet[0]
EndFunc ;==>_lua_toCFunction
;~ LUA_API void *(lua_touserdata) (lua_State *L, int idx);
Func _lua_toUserdata($pState, $iIdx)
Local $aRet = DllCall($__gLua_hDLL, "ptr:cdecl", "lua_touserdata", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, 0)
Return $aRet[0]
EndFunc ;==>_lua_toUserdata
;~ LUA_API lua_State *(lua_tothread) (lua_State *L, int idx);
Func _lua_toThread($pState, $iIdx)
Local $aRet = DllCall($__gLua_hDLL, "ptr:cdecl", "lua_tothread", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, 0)
Return $aRet[0]
EndFunc ;==>_lua_toThread
;~ LUA_API const void *(lua_topointer) (lua_State *L, int idx);
Func _lua_toPointer($pState, $iIdx)
Local $aRet = DllCall($__gLua_hDLL, "ptr:cdecl", "lua_topointer", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, 0)
Return $aRet[0]
EndFunc ;==>_lua_toPointer
; -----------------------------------
; Comparison and arithmetic functions
; -----------------------------------
;~ LUA_API void (lua_arith) (lua_State *L, int op);
Func _lua_arith($pState, $iOp)
DllCall($__gLua_hDLL, "none:cdecl", "lua_arith", "ptr", $pState, "int", $iOp)
EndFunc ;==>_lua_arith
;~ LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2);
Func _lua_rawEqual($pState, $iIdx1, $iIdx2)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_rawequal", "ptr", $pState, "int", $iIdx1, "int", $iIdx2)
If @error Then Return SetError(@error, 0, 0)
Return $aRet[0]
EndFunc ;==>_lua_rawEqual
;~ LUA_API int (lua_compare) (lua_State *L, int idx1, int idx2, int op);
Func _lua_compare($pState, $iIdx1, $iIdx2, $iOp)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_compare", "ptr", $pState, "int", $iIdx1, "int", $iIdx2, "int", $iOp)
If @error Then Return SetError(@error, 0, 0)
Return $aRet[0]
EndFunc ;==>_lua_compare
; ---------------------------
; Push functions (C -> stack)
; ---------------------------
;~ LUA_API void (lua_pushnil) (lua_State *L);
Func _lua_pushNil($pState)
DllCall($__gLua_hDLL, "none:cdecl", "lua_pushnil", "ptr", $pState)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_pushNil
;~ LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
Func _lua_pushNumber($pState, $fNumber)
DllCall($__gLua_hDLL, "none:cdecl", "lua_pushnumber", "ptr", $pState, "double", $fNumber)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_pushNumber
;~ LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
Func _lua_pushInteger($pState, $iInteger)
DllCall($__gLua_hDLL, "none:cdecl", "lua_pushinteger", "ptr", $pState, "int64", $iInteger)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_pushInteger
;~ LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t len);
;~ LUA_API const char *(lua_pushstring) (lua_State *L, const char *s);
;~ LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt, va_list argp);
;~ LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
Func _lua_pushString($pState, $sString)
Local $tBuf = __lua_helper_str2buf($sString)
Local $iSize = @extended
DllCall($__gLua_hDLL, "ptr:cdecl", "lua_pushlstring", "ptr", $pState, "struct*", $tBuf, "ulong_ptr", $iSize)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_pushString
Func _lua_pushBinary($pState, $bBinary)
Local $tBuf = DllStructCreate("byte[" & BinaryLen($bBinary) & "]")
DllStructSetData($tBuf, 1, $bBinary)
DllCall($__gLua_hDLL, "ptr:cdecl", "lua_pushlstring", "ptr", $pState, "struct*", $tBuf, "ulong_ptr", BinaryLen($bBinary))
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_pushBinary
;~ LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
Func _lua_pushCClosure($pState, $pfnCFunction, $iN)
DllCall($__gLua_hDLL, "none:cdecl", "lua_pushcclosure", "ptr", $pState, "ptr", __lua_helper_regFunc($pfnCFunction, "int:cdecl", "ptr"), "int", $iN)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_pushCClosure
;~ LUA_API void (lua_pushboolean) (lua_State *L, int b);
Func _lua_pushBoolean($pState, $bBoolean)
DllCall($__gLua_hDLL, "none:cdecl", "lua_pushboolean", "ptr", $pState, "int", $bBoolean ? 1 : 0)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_pushBoolean
;~ LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p);
Func _lua_pushLightUserdata($pState, $pUserData)
DllCall($__gLua_hDLL, "none:cdecl", "lua_pushlightuserdata", "ptr", $pState, "ptr", $pUserData)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_pushLightUserdata
;~ LUA_API int (lua_pushthread) (lua_State *L);
Func _lua_pushThread($pState)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_pushthread", "ptr", $pState)
If @error Then Return SetError(@error, 0, 0)
Return $aRet[0]
EndFunc ;==>_lua_pushThread
; ----------------------------
; Get functions (Lua -> stack)
; ----------------------------
;~ LUA_API int (lua_getglobal) (lua_State *L, const char *name);
Func _lua_getGlobal($pState, $sName)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_getglobal", "ptr", $pState, "str", $sName)
If @error Then Return SetError(@error, 0, $LUA_TNONE)
Return $aRet[0]
EndFunc ;==>_lua_getGlobal
;~ LUA_API int (lua_gettable) (lua_State *L, int idx);
Func _lua_getTable($pState, $iIdx)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_gettable", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, $LUA_TNONE)
Return $aRet[0]
EndFunc ;==>_lua_getTable
;~ LUA_API int (lua_getfield) (lua_State *L, int idx, const char *k);
Func _lua_getField($pState, $iIdx, $sKey)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_getfield", "ptr", $pState, "int", $iIdx, "str", $sKey)
If @error Then Return SetError(@error, 0, $LUA_TNONE)
Return $aRet[0]
EndFunc ;==>_lua_getField
;~ LUA_API int (lua_geti) (lua_State *L, int idx, lua_Integer n);
Func _lua_getI($pState, $iIdx, $iN)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_geti", "ptr", $pState, "int", $iIdx, "int64", $iN)
If @error Then Return SetError(@error, 0, $LUA_TNONE)
Return $aRet[0]
EndFunc ;==>_lua_getI
;~ LUA_API int (lua_rawget) (lua_State *L, int idx);
Func _lua_rawGet($pState, $iIdx)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_rawget", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, $LUA_TNONE)
Return $aRet[0]
EndFunc ;==>_lua_rawGet
;~ LUA_API int (lua_rawgeti) (lua_State *L, int idx, lua_Integer n);
Func _lua_rawGetI($pState, $iIdx, $iN)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_rawgeti", "ptr", $pState, "int", $iIdx, "int64", $iN)
If @error Then Return SetError(@error, 0, $LUA_TNONE)
Return $aRet[0]
EndFunc ;==>_lua_rawGetI
;~ LUA_API int (lua_rawgetp) (lua_State *L, int idx, const void *p);
Func _lua_rawGetP($pState, $iIdx, $pK)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_rawgetp", "ptr", $pState, "int", $iIdx, "ptr", $pK)
If @error Then Return SetError(@error, 0, $LUA_TNONE)
Return $aRet[0]
EndFunc ;==>_lua_rawGetP
;~ LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
Func _lua_createTable($pState, $nArr, $nRec)
DllCall($__gLua_hDLL, "none:cdecl", "lua_createtable", "ptr", $pState, "int", $nArr, "int", $nRec)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_createTable
;~ LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
Func _lua_newUserdata($pState, $iSize)
Local $aRet = DllCall($__gLua_hDLL, "ptr:cdecl", "lua_newuserdata", "ptr", $pState, "ulong_ptr", $iSize)
If @error Then Return SetError(@error, 0, 0)
Return $aRet[0]
EndFunc ;==>_lua_newUserdata
;~ LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
Func _lua_getMetatable($pState, $iIdx)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_getmetatable", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, False)
Return $aRet[0] <> 0
EndFunc ;==>_lua_getMetatable
;~ LUA_API int (lua_getuservalue) (lua_State *L, int idx);
Func _lua_getUservalue($pState, $iIdx)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_getuservalue", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, $LUA_TNONE)
Return $aRet[0]
EndFunc ;==>_lua_getUservalue
; ----------------------------
; Set functions (stack -> Lua)
; ----------------------------
;~ LUA_API void (lua_setglobal) (lua_State *L, const char *name);
Func _lua_setGlobal($pState, $sName)
DllCall($__gLua_hDLL, "none:cdecl", "lua_setglobal", "ptr", $pState, "str", $sName)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_setGlobal
;~ LUA_API void (lua_settable) (lua_State *L, int idx);
Func _lua_setTable($pState, $iIdx)
DllCall($__gLua_hDLL, "none:cdecl", "lua_settable", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_setTable
;~ LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
Func _lua_setField($pState, $iIdx, $sKey)
DllCall($__gLua_hDLL, "none:cdecl", "lua_setfield", "ptr", $pState, "int", $iIdx, "str", $sKey)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_setField
;~ LUA_API void (lua_seti) (lua_State *L, int idx, lua_Integer n);
Func _lua_setI($pState, $iIdx, $iN)
DllCall($__gLua_hDLL, "none:cdecl", "lua_seti", "ptr", $pState, "int", $iIdx, "int64", $iN)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_setI
;~ LUA_API void (lua_rawset) (lua_State *L, int idx);
Func _lua_rawSet($pState, $iIdx)
DllCall($__gLua_hDLL, "none:cdecl", "lua_rawset", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_rawSet
;~ LUA_API void (lua_rawseti) (lua_State *L, int idx, lua_Integer n);
Func _lua_rawSetI($pState, $iIdx, $iN)
DllCall($__gLua_hDLL, "none:cdecl", "lua_rawseti", "ptr", $pState, "int", $iIdx, "int64", $iN)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_rawSetI
;~ LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p);
Func _lua_rawSetP($pState, $iIdx, $pK)
DllCall($__gLua_hDLL, "none:cdecl", "lua_rawsetp", "ptr", $pState, "int", $iIdx, "ptr", $pK)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_rawSetP
;~ LUA_API int (lua_setmetatable) (lua_State *L, int objindex); ????? in the online manual, return value is void
Func _lua_setMetatable($pState, $iIdx)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_setmetatable", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, False)
Return $aRet[0]
EndFunc ;==>_lua_setMetatable
;~ LUA_API void (lua_setuservalue) (lua_State *L, int idx);
Func _lua_setUservalue($pState, $iIdx)
DllCall($__gLua_hDLL, "none:cdecl", "lua_setuservalue", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_setUservalue
; ---------------------------------------------------
; 'load' and 'call' functions (load and run Lua code)
; ---------------------------------------------------
;~ LUA_API void (lua_callk) (lua_State *L, int nargs, int nresults,lua_KContext ctx, lua_KFunction k);
;~ #define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL)
Func _lua_call($pState, $iNArgs, $iNResults = $LUA_MULTRET, $pKContext = Null, $pKFunction = Null)
DllCall($__gLua_hDLL, "none:cdecl", "lua_callk", "ptr", $pState, "int", $iNArgs, "int", $iNResults, "ptr", $pKContext, "ptr", $pKFunction)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_call
;~ LUA_API int (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc, lua_KContext ctx, lua_KFunction k);
;~ #define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL)
Func _lua_pCall($pState, $iNArgs, $iNResults = $LUA_MULTRET, $iErrFuncIdx = 0, $pKContext = Null, $pKFunction = Null)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_pcallk", "ptr", $pState, "int", $iNArgs, "int", $iNResults, "int", $iErrFuncIdx, "ptr", $pKContext, "ptr", $pKFunction)
If @error Then Return SetError(@error, 0, $LUA_ERRRUN)
Return $aRet[0]
EndFunc ;==>_lua_pCall
;~ LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt, const char *chunkname, const char *mode);
Func _lua_load($pState, $vData, $sChunkname = "", $sMode = "bt")
Local $tUserData = DllStructCreate("ptr Buf; ulong_ptr Size; bool Done")
Local $tBuf = __lua_helper_str2buf($vData, False)
Local $iSize = @extended
$tUserData.Buf = DllStructGetPtr($tBuf)
$tUserData.Size = $iSize
$tUserData.Done = False
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_load", _
"ptr", $pState, _
"ptr", __lua_helper_regFunc(__lua_load_reader, "ptr:cdecl", "ptr;ptr;ulong_ptr"), _
"struct*", $tUserData, _
"str", $sChunkname, "str", $sMode _
)
If @error Then Return SetError(@error, 0, -1)
Return $aRet[0]
EndFunc ;==>_lua_load
Func __lua_load_reader($pState, $pUserData, $pSize)
Local $tUserData = DllStructCreate("ptr Buf; ulong_ptr Size; bool Done", $pUserData)
If Not $tUserData.Done Then
DllStructSetData(DllStructCreate("ulong_ptr", $pSize), 1, $tUserData.Size)
$tUserData.Done = True
Return $tUserData.Buf
Else
Return Null
EndIf
EndFunc ;==>__lua_load_reader
;~ LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data, int strip);
Func _lua_dump($pState, $bStrip = False)
Local $tUserData = DllStructCreate("handle Heap; ptr Mem; ulong_ptr Size; ulong_ptr Offset")
$tUserData.Heap = DllCall("kernel32.dll", "handle", "GetProcessHeap")[0]
$tUserData.Mem = DllCall("kernel32.dll", "ptr", "HeapAlloc", "handle", $tUserData.Heap, "dword", 0, "ulong_ptr", 4096)[0]
$tUserData.Size = 4096
$tUserData.Offset = 0
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_dump", "ptr", $pState, "ptr", __lua_helper_regFunc(__lua_dump_writer, "int:cdecl", "ptr;ptr;ulong_ptr;ptr"), "struct*", $tUserData, "int", $bStrip)
If @error Then Return SetError(@error, 0, -1)
If $aRet[0] = 0 Then
$aRet[0] = DllStructGetData(DllStructCreate("byte[" & $tUserData.Offset & "]", $tUserData.Mem), 1)
Else
SetError($aRet[0])
$aRet[0] = -1
EndIf
DllCall("kernel32", "bool", "HeapFree", "handle", $tUserData.Heap, "dword", 0, "ptr", $tUserData.Mem)
Return $aRet[0]
EndFunc ;==>_lua_dump
Func __lua_dump_writer($pState, $pData, $iSize, $pUserData)
Local $tUserData = DllStructCreate("handle Heap; ptr Mem; ulong_ptr Size; ulong_ptr Offset", $pUserData)
While $tUserData.Size < $tUserData.Offset + $iSize
$tUserData.Mem = DllCall("kernel32.dll", "ptr", "HeapReAlloc", "handle", $tUserData.Heap, "dword", 0, "ptr", $tUserData.Mem, "ulong_ptr", $tUserData.Size + 4096)
$tUserData.Size += 4096
WEnd
DllCall("kernel32.dll", "none", "RtlMoveMemory", "struct*", $pData, "struct*", $tUserData.Mem + $tUserData.Offset, "ulong_ptr", $iSize) ; avoid Memory.au3 depandancy
$tUserData.Offset += $iSize
Return 0
EndFunc ;==>__lua_dump_writer
; -------------------
; coroutine functions
; -------------------
; will this work with AutoIt???
;~ LUA_API int (lua_yieldk) (lua_State *L, int nresults, lua_KContext ctx, lua_KFunction k);
;~ #define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL)
Func _lua_yield($pState, $iNResults, $pKContext = Null, $pKFunction = Null)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_yieldk", "ptr", $pState, "int", $iNResults, "ptr", $pKContext, "ptr", $pKFunction)
If @error Then Return SetError(@error, 0, 0)
Return $aRet[0]
EndFunc ;==>_lua_yield
;~ LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg);
Func _lua_resume($pState, $pFromState, $iNArgs)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_resume", "ptr", $pState, "ptr", $pFromState, "int", $iNArgs)
If @error Then Return SetError(@error, 0, 0)
Return $aRet[0]
EndFunc ;==>_lua_resume
;~ LUA_API int (lua_status) (lua_State *L);
Func _lua_status($pState)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_status", "ptr", $pState)
If @error Then Return SetError(@error, 0, -1)
Return $aRet[0]
EndFunc ;==>_lua_status
;~ LUA_API int (lua_isyieldable) (lua_State *L);
Func _lua_isYieldable($pState)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_isyieldable", "ptr", $pState)
If @error Then Return SetError(@error, 0, 0)
Return $aRet[0]
EndFunc ;==>_lua_isYieldable
; ---------------------------------------
; garbage-collection function and options
; ---------------------------------------
;~ LUA_API int (lua_gc) (lua_State *L, int what, int data);
Func _lua_gc($pState, $iWhat, $iData)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_gc", "ptr", $pState, "int", $iWhat, "int", $iData)
If @error Then Return SetError(@error, 0, 0)
Return $aRet[0]
EndFunc ;==>_lua_gc
; -----------------------
; miscellaneous functions
; -----------------------
;~ LUA_API int (lua_error) (lua_State *L);
Func _lua_error($pState)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_error", "ptr", $pState)
If @error Then Return SetError(@error, 0, 0)
Return $aRet[0] ; function never returns
EndFunc ;==>_lua_error
;~ LUA_API int (lua_next) (lua_State *L, int idx);
Func _lua_next($pState, $iIdx)
Local $aRet = DllCall($__gLua_hDLL, "int:cdecl", "lua_next", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, 0)
Return $aRet[0]
EndFunc ;==>_lua_next
;~ LUA_API void (lua_concat) (lua_State *L, int n);
Func _lua_concat($pState, $iN)
DllCall($__gLua_hDLL, "none:cdecl", "lua_concat", "ptr", $pState, "int", $iN)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_concat
;~ LUA_API void (lua_len) (lua_State *L, int idx);
Func _lua_len($pState, $iIdx)
DllCall($__gLua_hDLL, "none:cdecl", "lua_len", "ptr", $pState, "int", $iIdx)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_len
;~ LUA_API size_t (lua_stringtonumber) (lua_State *L, const char *s);
Func _lua_stringToNumber($pState, $sString)
Local $aRet = DllCall($__gLua_hDLL, "ulong_ptr:cdecl", "lua_stringtonumber", "ptr", $pState, "str", $sString)
If @error Then Return SetError(@error, 0, 0)
Return $aRet[0]
EndFunc ;==>_lua_stringToNumber
;~ LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
Func _lua_getAllocF($pState)
Local $aRet = DllCall($__gLua_hDLL, "ptr:cdecl", "lua_getallocf", "ptr", $pState, "ptr*", 0)
If @error Then Return SetError(@error, 0, Null)
Return SetError(0, $aRet[2], $aRet[0])
EndFunc ;==>_lua_getAllocF
;~ LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
Func _lua_setAllocF($pState, $pfnAlloc, $pUserData = Null)
DllCall($__gLua_hDLL, "none:cdecl", "lua_setallocf", "ptr", $pState, "ptr", __lua_helper_regFunc($pfnAlloc, "ptr:cdecl", "ptr;ptr;ulong_ptr;ulong_ptr"), "ptr", $pUserData)
If @error Then Return SetError(@error, 0, False)
Return True
EndFunc ;==>_lua_setAllocF
; ------------------
; some useful macros
; ------------------
; not really needed
;~ #define lua_getextraspace(L) ((void *)((char *)(L) - LUA_EXTRASPACE))
; already defined
;~ #define lua_tonumber(L,i) lua_tonumberx(L,(i),NULL)
;~ #define lua_tointeger(L,i) lua_tointegerx(L,(i),NULL)
;~ #define lua_pop(L,n) lua_settop(L, -(n)-1)
Func _lua_pop($pState, $iN)
_lua_setTop($pState, (-1 * $iN) - 1)
EndFunc ;==>_lua_pop
;~ #define lua_newtable(L) lua_createtable(L, 0, 0)
Func _lua_newTable($pState)
Local $vRet = _lua_createTable($pState, 0, 0)
Return SetError(@error, @extended, $vRet)