FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
lowlua/lowlua/lowlua.cpp at master · garrysmodlua/lowlua · GitHub
This repository was archived by the owner on Oct 5, 2020. It is now read-only.
garrysmodlua
lowlua
Repository navigation
Code
Issues
3
(3)
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
lowlua
/
lowlua
/
lowlua.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
586 lines (513 loc) · 17.8 KB
Breadcrumbs
lowlua
/
lowlua
/
lowlua.cpp
Copy path
File metadata and controls
586 lines (513 loc) · 17.8 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
"
luainterface.h
"
#
include
"
luabase.h
"
#
include
"
luatypes.h
"
#
include
"
dispatch.h
"
#
include
"
const.h
"
#
include
"
macros.h
"
#
include
"
lowlua.h
"
static
const
std::vector<luaL_Reg> lowlua_lib = {
#
pragma
region Basic stack manipulation
{
"
lua_gettop
"
, proto_lua_gettop },
{
"
lua_settop
"
, proto_lua_settop },
{
"
lua_pushvalue
"
, proto_lua_pushvalue },
{
"
lua_remove
"
, proto_lua_remove },
{
"
lua_insert
"
, proto_lua_insert },
{
"
lua_replace
"
, proto_lua_replace },
{
"
lua_checkstack
"
, proto_lua_checkstack },
#
pragma
endregion
#
pragma
region Access functions (stack -> C)
{
"
lua_isnone
"
, proto_lua_isnone },
{
"
lua_isnil
"
, proto_lua_isnil },
{
"
lua_isnoneornil
"
, proto_lua_isnoneornil },
{
"
lua_isboolean
"
, proto_lua_isboolean },
{
"
lua_isnumber
"
, proto_lua_isnumber },
{
"
lua_isstring
"
, proto_lua_isstring },
{
"
lua_istable
"
, proto_lua_istable },
{
"
lua_iscfunction
"
, proto_lua_iscfunction },
{
"
lua_isuserdata
"
, proto_lua_isuserdata },
{
"
lua_isthread
"
, proto_lua_isthread },
{
"
lua_toboolean
"
, proto_lua_toboolean },
{
"
lua_tointeger
"
, proto_lua_tointeger },
{
"
lua_tonumber
"
, proto_lua_tonumber },
{
"
lua_tostring
"
, proto_lua_tostring },
{
"
lua_tolstring
"
, proto_lua_tolstring },
{
"
lua_tocfunction
"
, proto_lua_tocfunction },
/*
{ "lua_touserdata", proto_lua_touserdata },
{ "lua_tothread", proto_lua_tothread },
{ "lua_topointer", proto_lua_topointer },
*/
{
"
lua_objlen
"
, proto_lua_objlen },
{
"
lua_type
"
, proto_lua_type },
{
"
lua_typename
"
, proto_lua_typename },
{
"
luaL_typename
"
, proto_luaL_typename },
#
pragma
endregion
#
pragma
region Push functions (C -> stack)
{
"
lua_pushnil
"
, proto_lua_pushnil },
{
"
lua_pushboolean
"
, proto_lua_pushboolean },
{
"
lua_pushinteger
"
, proto_lua_pushinteger },
{
"
lua_pushnumber
"
, proto_lua_pushnumber },
{
"
lua_pushstring
"
, proto_lua_pushstring },
{
"
lua_pushlstring
"
, proto_lua_pushlstring },
{
"
lua_pushcclosure
"
, proto_lua_pushcclosure },
#
pragma
endregion
#
pragma
region Get functions (Lua -> stack)
{
"
lua_gettable
"
, proto_lua_gettable },
{
"
lua_getfield
"
, proto_lua_getfield },
{
"
lua_rawget
"
, proto_lua_rawget },
{
"
lua_rawgeti
"
, proto_lua_rawgeti },
{
"
lua_createtable
"
, proto_lua_createtable },
//
{ "lua_newuserdata", proto_lua_newuserdata },
{
"
lua_getmetatable
"
, proto_lua_getmetatable },
{
"
lua_getfenv
"
, proto_lua_getfenv },
#
pragma
endregion
#
pragma
region Set functions (stack -> Lua)
{
"
lua_settable
"
, proto_lua_settable },
{
"
lua_setfield
"
, proto_lua_setfield },
{
"
lua_rawset
"
, proto_lua_rawset },
{
"
lua_rawseti
"
, proto_lua_rawseti },
{
"
lua_setmetatable
"
, proto_lua_setmetatable },
{
"
lua_setfenv
"
, proto_lua_setfenv },
#
pragma
endregion
#
pragma
region Call functions
{
"
lua_call
"
, proto_lua_call },
{
"
lua_pcall
"
, proto_lua_pcall }
#
pragma
endregion
//
{ nullptr, nullptr } // NOTE: Do not add the trailing null! A workaround has been introduced since "luaL_register" function does not work as expected - redesigned (adding a trailing null would crash)... Thanks to Garry for screwing it.
};
static
const
std::vector<luaX_Const<
int
>> lowlua_ints = {
{
"
LUA_ERRFILE
"
,
LUA_ERRFILE
},
{
"
LUA_NOREF
"
,
LUA_NOREF
},
{
"
LUA_REFNIL
"
,
LUA_REFNIL
},
{
"
LUA_VERSION_NUM
"
,
LUA_VERSION_NUM
},
{
"
LUA_MULTRET
"
,
LUA_MULTRET
},
{
"
LUA_REGISTRYINDEX
"
,
LUA_REGISTRYINDEX
},
{
"
LUA_ENVIRONINDEX
"
,
LUA_ENVIRONINDEX
},
{
"
LUA_GLOBALSINDEX
"
,
LUA_GLOBALSINDEX
},
{
"
LUA_YIELD
"
,
LUA_YIELD
},
{
"
LUA_ERRRUN
"
,
LUA_ERRRUN
},
{
"
LUA_ERRSYNTAX
"
,
LUA_ERRSYNTAX
},
{
"
LUA_ERRMEM
"
,
LUA_ERRMEM
},
{
"
LUA_ERRERR
"
,
LUA_ERRERR
},
{
"
LUA_TNONE
"
,
LUA_TNONE
},
{
"
LUA_TNIL
"
,
LUA_TNIL
},
{
"
LUA_TBOOLEAN
"
,
LUA_TBOOLEAN
},
{
"
LUA_TLIGHTUSERDATA
"
,
LUA_TLIGHTUSERDATA
},
{
"
LUA_TNUMBER
"
,
LUA_TNUMBER
},
{
"
LUA_TSTRING
"
,
LUA_TSTRING
},
{
"
LUA_TTABLE
"
,
LUA_TTABLE
},
{
"
LUA_TFUNCTION
"
,
LUA_TFUNCTION
},
{
"
LUA_TUSERDATA
"
,
LUA_TUSERDATA
},
{
"
LUA_TTHREAD
"
,
LUA_TTHREAD
},
{
"
LUA_MINSTACK
"
,
LUA_MINSTACK
},
{
"
LUA_GCSTOP
"
,
LUA_GCSTOP
},
{
"
LUA_GCRESTART
"
,
LUA_GCRESTART
},
{
"
LUA_GCCOLLECT
"
,
LUA_GCCOLLECT
},
{
"
LUA_GCCOUNT
"
,
LUA_GCCOUNT
},
{
"
LUA_GCCOUNTB
"
,
LUA_GCCOUNTB
},
{
"
LUA_GCSTEP
"
,
LUA_GCSTEP
},
{
"
LUA_GCSETPAUSE
"
,
LUA_GCSETPAUSE
},
{
"
LUA_GCSETSTEPMUL
"
,
LUA_GCSETSTEPMUL
},
{
"
LUA_HOOKCALL
"
,
LUA_HOOKCALL
},
{
"
LUA_HOOKRET
"
,
LUA_HOOKRET
},
{
"
LUA_HOOKLINE
"
,
LUA_HOOKLINE
},
{
"
LUA_HOOKCOUNT
"
,
LUA_HOOKCOUNT
},
{
"
LUA_HOOKTAILRET
"
,
LUA_HOOKTAILRET
},
{
"
LUA_MASKCALL
"
,
LUA_MASKCALL
},
{
"
LUA_MASKRET
"
,
LUA_MASKRET
},
{
"
LUA_MASKLINE
"
,
LUA_MASKLINE
},
{
"
LUA_MASKCOUNT
"
,
LUA_MASKCOUNT
},
{
"
WINVER
"
,
WINVER
},
{
"
LUAI_MAXSTACK
"
,
LUAI_MAXSTACK
},
{
"
LUAI_MAXCSTACK
"
,
LUAI_MAXCSTACK
},
{
"
LUAI_GCPAUSE
"
,
LUAI_GCPAUSE
},
{
"
LUAI_GCMUL
"
,
LUAI_GCMUL
},
{
"
LUA_MAXCAPTURES
"
,
LUA_MAXCAPTURES
},
{
"
LUA_IDSIZE
"
,
LUA_IDSIZE
},
{
"
LUAL_BUFFERSIZE
"
,
LUAL_BUFFERSIZE
},
{
"
LUAI_MAXNUMBER2STR
"
,
LUAI_MAXNUMBER2STR
},
{
"
LUAJIT_VERSION_NUM
"
,
LUAJIT_VERSION_NUM
},
{
"
LUAJIT_MODE_MASK
"
,
LUAJIT_MODE_MASK
},
{
"
LUAJIT_MODE_OFF
"
,
LUAJIT_MODE_OFF
},
{
"
LUAJIT_MODE_ON
"
,
LUAJIT_MODE_ON
},
{
"
LUAJIT_MODE_FLUSH
"
,
LUAJIT_MODE_FLUSH
}
};
static
const
std::vector<luaX_Const<
const
char
*>> lowlua_strings = {
{
"
LUA_VERSION
"
,
LUA_VERSION
},
{
"
LUA_RELEASE
"
,
LUA_RELEASE
},
{
"
LUA_COPYRIGHT
"
,
LUA_COPYRIGHT
},
{
"
LUA_AUTHORS
"
,
LUA_AUTHORS
},
{
"
LUA_SIGNATURE
"
,
LUA_SIGNATURE
},
{
"
LUA_LDIR
"
,
LUA_LDIR
},
{
"
LUA_CDIR
"
,
LUA_CDIR
},
{
"
LUA_PATH_DEFAULT
"
,
LUA_PATH_DEFAULT
},
{
"
LUA_CPATH_DEFAULT
"
,
LUA_CPATH_DEFAULT
},
{
"
LUA_PATH
"
,
LUA_PATH
},
{
"
LUA_CPATH
"
,
LUA_CPATH
},
{
"
LUA_INIT
"
,
LUA_INIT
},
{
"
LUA_DIRSEP
"
,
LUA_DIRSEP
},
{
"
LUA_PATHSEP
"
,
LUA_PATHSEP
},
{
"
LUA_PATH_MARK
"
,
LUA_PATH_MARK
},
{
"
LUA_EXECDIR
"
,
LUA_EXECDIR
},
{
"
LUA_IGMARK
"
,
LUA_IGMARK
},
{
"
LUA_PATH_CONFIG
"
,
LUA_PATH_CONFIG
},
{
"
LUA_QS
"
,
LUA_QS
},
{
"
LUA_NUMBER_SCAN
"
,
LUA_NUMBER_SCAN
},
{
"
LUA_NUMBER_FMT
"
,
LUA_NUMBER_FMT
},
{
"
LUA_INTFRMLEN
"
,
LUA_INTFRMLEN
},
{
"
LUAJIT_VERSION
"
,
LUAJIT_VERSION
},
{
"
LUAJIT_COPYRIGHT
"
,
LUAJIT_COPYRIGHT
},
{
"
LUAJIT_URL
"
,
LUAJIT_URL
},
{
"
LUA_FILEHANDLE
"
,
LUA_FILEHANDLE
},
{
"
LUA_COLIBNAME
"
,
LUA_COLIBNAME
},
{
"
LUA_MATHLIBNAME
"
,
LUA_MATHLIBNAME
},
{
"
LUA_STRLIBNAME
"
,
LUA_STRLIBNAME
},
{
"
LUA_TABLIBNAME
"
,
LUA_TABLIBNAME
},
{
"
LUA_IOLIBNAME
"
,
LUA_IOLIBNAME
},
{
"
LUA_OSLIBNAME
"
,
LUA_OSLIBNAME
},
{
"
LUA_LOADLIBNAME
"
,
LUA_LOADLIBNAME
},
{
"
LUA_DBLIBNAME
"
,
LUA_DBLIBNAME
},
{
"
LUA_BITLIBNAME
"
,
LUA_BITLIBNAME
},
{
"
LUA_JITLIBNAME
"
,
LUA_JITLIBNAME
},
{
"
LUA_FFILIBNAME
"
,
LUA_FFILIBNAME
}
};
//
Called by Garry's Mod, when a module is opened (using the "require" function).
GMOD_MODULE_OPEN
() {
//
Register <lowlua_lib> functions into the <_G> table.
luaX_dispatch<
DISPATCH
::
ENTRY_POINT_EVENT
>(L,
LUA_GLOBALSINDEX
, lowlua_lib);
//
luaX_dispatch_const<DISPATCH::ENTRY_POINT_EVENT, int>(L, LUA_GLOBALSINDEX, lowlua_ints);
luaX_dispatch_const_int<
DISPATCH
::
ENTRY_POINT_EVENT
>(L,
LUA_GLOBALSINDEX
, lowlua_ints);
//
luaX_dispatch_const<DISPATCH::ENTRY_POINT_EVENT, const char*>(L, LUA_GLOBALSINDEX, lowlua_strings);
luaX_dispatch_const_string<
DISPATCH
::
ENTRY_POINT_EVENT
>(L,
LUA_GLOBALSINDEX
, lowlua_strings);
return
0
;
}
//
Called by Garry's Mod, when a module is closed (i.e. on disconnect/shutdown, or by using the "unrequire" module).
GMOD_MODULE_CLOSE
() {
//
Unregister <lowlua_lib> functions from the <_G> table.
luaX_dispatch<
DISPATCH
::
EXIT_POINT_EVENT
>(L,
LUA_GLOBALSINDEX
, lowlua_lib);
//
luaX_dispatch_const<DISPATCH::EXIT_POINT_EVENT, int>(L, LUA_GLOBALSINDEX, lowlua_ints);
luaX_dispatch_const_int<
DISPATCH
::
EXIT_POINT_EVENT
>(L,
LUA_GLOBALSINDEX
, lowlua_ints);
//
luaX_dispatch_const<DISPATCH::EXIT_POINT_EVENT, const char*>(L, LUA_GLOBALSINDEX, lowlua_strings);
luaX_dispatch_const_string<
DISPATCH
::
EXIT_POINT_EVENT
>(L,
LUA_GLOBALSINDEX
, lowlua_strings);
return
0
;
}
#
pragma
region Basic stack manipulation
LUA_STATIC_FUNCTION
(proto_lua_gettop) {
const
lua_Integer gettop =
static_cast
<lua_Integer>(
lua_gettop
(L));
lua_pushinteger
(L, gettop);
return
1
;
}
LUA_STATIC_FUNCTION
(proto_lua_settop) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
lua_settop
(L, idx);
return
0
;
}
LUA_STATIC_FUNCTION
(proto_lua_pushvalue) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
lua_pushvalue
(L, idx);
return
0
;
}
LUA_STATIC_FUNCTION
(proto_lua_remove) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
lua_remove
(L, idx);
return
0
;
}
LUA_STATIC_FUNCTION
(proto_lua_insert) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
lua_insert
(L, idx);
return
0
;
}
LUA_STATIC_FUNCTION
(proto_lua_replace) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
lua_replace
(L, idx);
return
0
;
}
LUA_STATIC_FUNCTION
(proto_lua_checkstack) {
const
int
sz =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
lua_Integer checkstack =
static_cast
<lua_Integer>(
lua_checkstack
(L, sz));
lua_pushinteger
(L, checkstack);
return
1
;
}
#
pragma
endregion
#
pragma
region Access functions (stack -> C)
LUA_STATIC_FUNCTION
(proto_lua_isnone) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
int
isnone =
lua_type
(L, idx) == GarrysMod::Lua::Type::
NONE
?
1
:
0
;
lua_pushboolean
(L, isnone);
return
1
;
}
LUA_STATIC_FUNCTION
(proto_lua_isnil) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
int
isnil =
lua_type
(L, idx) == GarrysMod::Lua::Type::
NIL
?
1
:
0
;
lua_pushboolean
(L, isnil);
return
1
;
}
LUA_STATIC_FUNCTION
(proto_lua_isnoneornil) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
int
isnoneornil =
lua_type
(L, idx) <= GarrysMod::Lua::Type::
NIL
?
1
:
0
;
lua_pushboolean
(L, isnoneornil);
return
1
;
}
LUA_STATIC_FUNCTION
(proto_lua_isboolean) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
int
isboolean =
lua_type
(L, idx) == GarrysMod::Lua::Type::
BOOLEAN
?
1
:
0
;
lua_pushboolean
(L, isboolean);
return
1
;
}
LUA_STATIC_FUNCTION
(proto_lua_isnumber) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
int
isnumber =
lua_isnumber
(L, idx);
lua_pushboolean
(L, isnumber);
return
1
;
}
LUA_STATIC_FUNCTION
(proto_lua_isstring) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
int
isstring =
lua_isstring
(L, idx);
lua_pushboolean
(L, isstring);
return
1
;
}
LUA_STATIC_FUNCTION
(proto_lua_istable) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
int
istable =
lua_type
(L, idx) == GarrysMod::Lua::Type::
TABLE
?
1
:
0
;
lua_pushboolean
(L, istable);
return
1
;
}
LUA_STATIC_FUNCTION
(proto_lua_iscfunction) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
int
iscfunction =
lua_iscfunction
(L, idx);
lua_pushboolean
(L, iscfunction);
return
1
;
}
LUA_STATIC_FUNCTION
(proto_lua_isuserdata) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
int
isuserdata =
lua_isuserdata
(L, idx);
lua_pushboolean
(L, isuserdata);
return
1
;
}
LUA_STATIC_FUNCTION
(proto_lua_isthread) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
int
istable =
lua_type
(L, idx) == GarrysMod::Lua::Type::
THREAD
?
1
:
0
;
lua_pushboolean
(L, istable);
return
1
;
}
LUA_STATIC_FUNCTION
(proto_lua_toboolean) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
int
b =
lua_toboolean
(L, idx);
lua_pushboolean
(L, b);
return
1
;
}
LUA_STATIC_FUNCTION
(proto_lua_tointeger) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
lua_Integer n =
lua_tointeger
(L, idx);
lua_pushinteger
(L, n);
return
1
;
}
LUA_STATIC_FUNCTION
(proto_lua_tonumber) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
lua_Number n =
lua_tonumber
(L, idx);
lua_pushnumber
(L, n);
return
1
;
}
LUA_STATIC_FUNCTION
(proto_lua_tostring) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
char
* s =
lua_tolstring
(L, idx,
nullptr
);
lua_pushstring
(L, s);
return
1
;
}
LUA_STATIC_FUNCTION
(proto_lua_tolstring) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
size_t
* len =
reinterpret_cast
<
size_t
*>(
luaL_checkinteger
(L,
2
));
const
char
* s =
lua_tolstring
(L, idx, len);
lua_pushstring
(L, s);
return
1
;
}
LUA_STATIC_FUNCTION
(proto_lua_tocfunction) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
lua_CFunction fn =
lua_tocfunction
(L, idx);
lua_pushcclosure
(L, fn,
0
);
return
1
;
}
/*
LUA_STATIC_FUNCTION(proto_lua_touserdata) {
const int idx = static_cast<int>(luaL_checkinteger(L, 1));
lua_touserdata(L, idx);
return 1;
}
LUA_STATIC_FUNCTION(proto_lua_tothread) {
const int idx = static_cast<int>(luaL_checkinteger(L, 1));
lua_tothread(L, idx);
return 1;
}
LUA_STATIC_FUNCTION(proto_lua_topointer) {
const int idx = static_cast<int>(luaL_checkinteger(L, 1));
lua_topointer(L, idx);
return 1;
}
*/
LUA_STATIC_FUNCTION
(proto_lua_objlen) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
lua_Number objlen =
static_cast
<lua_Number>(
lua_objlen
(L, idx));
lua_pushnumber
(L, objlen);
return
1
;
}
LUA_STATIC_FUNCTION
(proto_lua_type) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
lua_Integer type_id =
static_cast
<lua_Integer>(
lua_type
(L, idx));
lua_pushinteger
(L, type_id);
return
1
;
}
LUA_STATIC_FUNCTION
(proto_lua_typename) {
const
int
tp =
clamp
(
static_cast
<
int
>(
luaL_checkinteger
(L,
1
)), GarrysMod::Lua::Type::
NONE
, GarrysMod::Lua::Type::
LAST
);
const
char
* type_name =
lua_typename
(L, tp);
//
lua_pushlstring(L, type_name, sizeof type_name / sizeof(char) - 1);
lua_pushstring
(L, type_name);
return
1
;
}
LUA_STATIC_FUNCTION
(proto_luaL_typename) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
char
* type_name =
lua_typename
(L,
lua_type
(L, idx));
//
lua_pushlstring(L, type_name, sizeof type_name / sizeof(char) - 1);
lua_pushstring
(L, type_name);
return
1
;
}
#
pragma
endregion
#
pragma
region Push functions (C -> stack)
LUA_STATIC_FUNCTION
(proto_lua_pushnil) {
lua_pushnil
(L);
return
0
;
}
LUA_STATIC_FUNCTION
(proto_lua_pushboolean) {
const
int
b =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
lua_pushboolean
(L, b);
return
0
;
}
LUA_STATIC_FUNCTION
(proto_lua_pushinteger) {
const
lua_Integer n =
luaL_checkinteger
(L,
1
);
lua_pushinteger
(L, n);
return
0
;
}
LUA_STATIC_FUNCTION
(proto_lua_pushnumber) {
const
lua_Number n =
luaL_checknumber
(L,
1
);
lua_pushnumber
(L, n);
return
0
;
}
LUA_STATIC_FUNCTION
(proto_lua_pushstring) {
const
char
* s =
luaL_checklstring
(L,
1
,
nullptr
);
lua_pushstring
(L, s);
return
0
;
}
LUA_STATIC_FUNCTION
(proto_lua_pushlstring) {
const
char
* s =
luaL_checklstring
(L,
1
,
nullptr
);
const
size_t
l =
static_cast
<
size_t
>(
luaL_checkinteger
(L,
2
));
lua_pushlstring
(L, s, l);
return
0
;
}
LUA_STATIC_FUNCTION
(proto_lua_pushcclosure) {
//
const lua_CFunction fn = luaL_checkcfunction(L, 1);
luaL_checktype
(L,
1
, GarrysMod::Lua::Type::
FUNCTION
);
const
lua_CFunction fn =
lua_tocfunction
(L,
1
);
const
int
n =
static_cast
<
int
>(
luaL_optinteger
(L,
2
,
static_cast
<lua_Integer>(
0
)));
lua_pushcclosure
(L, fn, n);
return
0
;
}
#
pragma
endregion
#
pragma
region Get functions (Lua -> stack)
LUA_STATIC_FUNCTION
(proto_lua_gettable) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
lua_gettable
(L, idx);
return
0
;
}
LUA_STATIC_FUNCTION
(proto_lua_getfield) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
char
* k =
luaL_checklstring
(L,
2
,
nullptr
);
lua_getfield
(L, idx, k);
return
0
;
}
LUA_STATIC_FUNCTION
(proto_lua_rawget) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
lua_rawget
(L, idx);
return
0
;
}
LUA_STATIC_FUNCTION
(proto_lua_rawgeti) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
int
n =
static_cast
<
int
>(
luaL_checkinteger
(L,
2
));
lua_rawgeti
(L, idx, n);
return
0
;
}
LUA_STATIC_FUNCTION
(proto_lua_createtable) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
int
nrec =
static_cast
<
int
>(
luaL_checkinteger
(L,
2
));
lua_createtable
(L, idx, nrec);
return
0
;
}
/*
LUA_STATIC_FUNCTION(proto_lua_newuserdata) {
const size_t sz = static_cast<size_t>(luaL_checkinteger(L, 1));
void* ud = lua_newuserdata(L, sz);
return 1;
}
*/
LUA_STATIC_FUNCTION
(proto_lua_getmetatable) {
const
int
objindex =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
lua_Integer getmetatable =
static_cast
<lua_Integer>(
lua_getmetatable
(L, objindex));
lua_pushinteger
(L, getmetatable);
return
1
;
}
LUA_STATIC_FUNCTION
(proto_lua_getfenv) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
lua_getfenv
(L, idx);
return
0
;
}
#
pragma
endregion
#
pragma
region Set functions (stack -> Lua)
LUA_STATIC_FUNCTION
(proto_lua_settable) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
lua_settable
(L, idx);
return
0
;
}
LUA_STATIC_FUNCTION
(proto_lua_setfield) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
char
* k =
luaL_checklstring
(L,
2
,
nullptr
);
lua_setfield
(L, idx, k);
return
0
;
}
LUA_STATIC_FUNCTION
(proto_lua_rawset) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
lua_rawset
(L, idx);
return
0
;
}
LUA_STATIC_FUNCTION
(proto_lua_rawseti) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
int
n =
static_cast
<
int
>(
luaL_checkinteger
(L,
2
));
lua_rawseti
(L, idx, n);
return
0
;
}
LUA_STATIC_FUNCTION
(proto_lua_setmetatable) {
const
int
objindex =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
lua_Integer setmetatable =
static_cast
<lua_Integer>(
lua_setmetatable
(L, objindex));
lua_pushinteger
(L, setmetatable);
return
1
;
}
LUA_STATIC_FUNCTION
(proto_lua_setfenv) {
const
int
idx =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
lua_Integer setfenv =
static_cast
<lua_Integer>(
lua_setfenv
(L, idx));
lua_pushinteger
(L, setfenv);
return
1
;
}
#
pragma
endregion
#
pragma
region Call functions
LUA_STATIC_FUNCTION
(proto_lua_call) {
const
int
nargs =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
int
nresults =
static_cast
<
int
>(
luaL_checkinteger
(L,
2
));
lua_call
(L, nargs, nresults);
return
0
;
}
LUA_STATIC_FUNCTION
(proto_lua_pcall) {
const
int
nargs =
static_cast
<
int
>(
luaL_checkinteger
(L,
1
));
const
int
nresults =
static_cast
<
int
>(
luaL_checkinteger
(L,
2
));
const
int
errfunc =
static_cast
<
int
>(
luaL_checkinteger
(L,
3
));
const
lua_Integer pcall =
static_cast
<lua_Integer>(
lua_pcall
(L, nargs, nresults, errfunc));
lua_pushinteger
(L, pcall);
return
1
;
}
#
pragma
endregion
Back
|
FazBrowse Home
|
New Git URL