-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
LuaDLL.cs
599 lines (468 loc) · 26.1 KB
/
LuaDLL.cs
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
/*
* Tencent is pleased to support the open source community by making xLua available.
* Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
namespace XLua.LuaDLL
{
using System;
using System.Runtime.InteropServices;
using System.Text;
using XLua;
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || XLUA_GENERAL || (UNITY_WSA && !UNITY_EDITOR)
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int lua_CSFunction(IntPtr L);
#if GEN_CODE_MINIMIZE
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int CSharpWrapperCaller(IntPtr L, int funcidx, int top);
#endif
#else
public delegate int lua_CSFunction(IntPtr L);
#if GEN_CODE_MINIMIZE
public delegate int CSharpWrapperCaller(IntPtr L, int funcidx, int top);
#endif
#endif
public partial class Lua
{
#if (UNITY_IPHONE || UNITY_TVOS || UNITY_WEBGL || UNITY_SWITCH) && !UNITY_EDITOR
const string LUADLL = "__Internal";
#else
const string LUADLL = "xlua";
#endif
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr lua_tothread(IntPtr L, int index);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int xlua_get_lib_version();
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int lua_gc(IntPtr L, LuaGCOptions what, int data);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr lua_getupvalue(IntPtr L, int funcindex, int n);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr lua_setupvalue(IntPtr L, int funcindex, int n);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int lua_pushthread(IntPtr L);
public static bool lua_isfunction(IntPtr L, int stackPos)
{
return lua_type(L, stackPos) == LuaTypes.LUA_TFUNCTION;
}
public static bool lua_islightuserdata(IntPtr L, int stackPos)
{
return lua_type(L, stackPos) == LuaTypes.LUA_TLIGHTUSERDATA;
}
public static bool lua_istable(IntPtr L, int stackPos)
{
return lua_type(L, stackPos) == LuaTypes.LUA_TTABLE;
}
public static bool lua_isthread(IntPtr L, int stackPos)
{
return lua_type(L, stackPos) == LuaTypes.LUA_TTHREAD;
}
public static int luaL_error(IntPtr L, string message) //[-0, +1, m]
{
xlua_csharp_str_error(L, message);
return 0;
}
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int lua_setfenv(IntPtr L, int stackPos);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr luaL_newstate();
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern void lua_close(IntPtr L);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] //[-0, +0, m]
public static extern void luaopen_xlua(IntPtr L);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] //[-0, +0, m]
public static extern void luaL_openlibs(IntPtr L);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern uint xlua_objlen(IntPtr L, int stackPos);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern void lua_createtable(IntPtr L, int narr, int nrec);//[-0, +0, m]
public static void lua_newtable(IntPtr L)//[-0, +0, m]
{
lua_createtable(L, 0, 0);
}
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int xlua_getglobal(IntPtr L, string name);//[-1, +0, m]
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int xlua_setglobal(IntPtr L, string name);//[-1, +0, m]
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern void xlua_getloaders(IntPtr L);
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern void lua_settop(IntPtr L, int newTop);
public static void lua_pop(IntPtr L, int amount)
{
lua_settop(L, -(amount) - 1);
}
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern void lua_insert(IntPtr L, int newTop);
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern void lua_remove(IntPtr L, int index);
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern int lua_rawget(IntPtr L, int index);
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern void lua_rawset(IntPtr L, int index);//[-2, +0, m]
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern int lua_setmetatable(IntPtr L, int objIndex);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int lua_rawequal(IntPtr L, int index1, int index2);
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern void lua_pushvalue(IntPtr L, int index);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern void lua_pushcclosure(IntPtr L, IntPtr fn, int n);//[-n, +1, m]
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern void lua_replace(IntPtr L, int index);
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern int lua_gettop(IntPtr L);
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern LuaTypes lua_type(IntPtr L, int index);
public static bool lua_isnil(IntPtr L, int index)
{
return (lua_type(L,index)==LuaTypes.LUA_TNIL);
}
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern bool lua_isnumber(IntPtr L, int index);
public static bool lua_isboolean(IntPtr L, int index)
{
return lua_type(L,index)==LuaTypes.LUA_TBOOLEAN;
}
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern int luaL_ref(IntPtr L, int registryIndex);
public static int luaL_ref(IntPtr L)//[-1, +0, m]
{
return luaL_ref(L,LuaIndexes.LUA_REGISTRYINDEX);
}
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern void xlua_rawgeti(IntPtr L, int tableIndex, long index);
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern void xlua_rawseti(IntPtr L, int tableIndex, long index);//[-1, +0, m]
public static void lua_getref(IntPtr L, int reference)
{
xlua_rawgeti(L,LuaIndexes.LUA_REGISTRYINDEX,reference);
}
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int pcall_prepare(IntPtr L, int error_func_ref, int func_ref);
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern void luaL_unref(IntPtr L, int registryIndex, int reference);
public static void lua_unref(IntPtr L, int reference)
{
luaL_unref(L,LuaIndexes.LUA_REGISTRYINDEX,reference);
}
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern bool lua_isstring(IntPtr L, int index);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool lua_isinteger(IntPtr L, int index);
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern void lua_pushnil(IntPtr L);
public static void lua_pushstdcallcfunction(IntPtr L, lua_CSFunction function, int n = 0)//[-0, +1, m]
{
#if XLUA_GENERAL || (UNITY_WSA && !UNITY_EDITOR)
GCHandle.Alloc(function);
#endif
IntPtr fn = Marshal.GetFunctionPointerForDelegate(function);
xlua_push_csharp_function(L, fn, n);
}
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int xlua_upvalueindex(int n);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int lua_pcall(IntPtr L, int nArgs, int nResults, int errfunc);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern double lua_tonumber(IntPtr L, int index);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int xlua_tointeger(IntPtr L, int index);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern uint xlua_touint(IntPtr L, int index);
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern bool lua_toboolean(IntPtr L, int index);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr lua_topointer(IntPtr L, int index);
[DllImport(LUADLL,CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr lua_tolstring(IntPtr L, int index, out IntPtr strLen);//[-0, +0, m]
public static string lua_tostring(IntPtr L, int index)
{
IntPtr strlen;
IntPtr str = lua_tolstring(L, index, out strlen);
if (str != IntPtr.Zero)
{
#if XLUA_GENERAL || (UNITY_WSA && !UNITY_EDITOR)
int len = strlen.ToInt32();
byte[] buffer = new byte[len];
Marshal.Copy(str, buffer, 0, len);
return Encoding.UTF8.GetString(buffer);
#else
string ret = Marshal.PtrToStringAnsi(str, strlen.ToInt32());
if (ret == null)
{
int len = strlen.ToInt32();
byte[] buffer = new byte[len];
Marshal.Copy(str, buffer, 0, len);
return Encoding.UTF8.GetString(buffer);
}
return ret;
#endif
}
else
{
return null;
}
}
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr lua_atpanic(IntPtr L, lua_CSFunction panicf);
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern void lua_pushnumber(IntPtr L, double number);
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern void lua_pushboolean(IntPtr L, bool value);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern void xlua_pushinteger(IntPtr L, int value);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern void xlua_pushuint(IntPtr L, uint value);
#if NATIVE_LUA_PUSHSTRING
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern void lua_pushstring(IntPtr L, string str);
#else
public static void lua_pushstring(IntPtr L, string str) //业务使用
{
if (str == null)
{
lua_pushnil(L);
}
else
{
#if !THREAD_SAFE && !HOTFIX_ENABLE
if (Encoding.UTF8.GetByteCount(str) > InternalGlobals.strBuff.Length)
{
byte[] bytes = Encoding.UTF8.GetBytes(str);
xlua_pushlstring(L, bytes, bytes.Length);
}
else
{
int bytes_len = Encoding.UTF8.GetBytes(str, 0, str.Length, InternalGlobals.strBuff, 0);
xlua_pushlstring(L, InternalGlobals.strBuff, bytes_len);
}
#else
var bytes = Encoding.UTF8.GetBytes(str);
xlua_pushlstring(L, bytes, bytes.Length);
#endif
}
}
#endif
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern void xlua_pushlstring(IntPtr L, byte[] str, int size);
public static void xlua_pushasciistring(IntPtr L, string str) // for inner use only
{
if (str == null)
{
lua_pushnil(L);
}
else
{
#if NATIVE_LUA_PUSHSTRING
lua_pushstring(L, str);
#else
#if !THREAD_SAFE && !HOTFIX_ENABLE
int str_len = str.Length;
if (InternalGlobals.strBuff.Length < str_len)
{
InternalGlobals.strBuff = new byte[str_len];
}
int bytes_len = Encoding.UTF8.GetBytes(str, 0, str_len, InternalGlobals.strBuff, 0);
xlua_pushlstring(L, InternalGlobals.strBuff, bytes_len);
#else
var bytes = Encoding.UTF8.GetBytes(str);
xlua_pushlstring(L, bytes, bytes.Length);
#endif
#endif
}
}
public static void lua_pushstring(IntPtr L, byte[] str)
{
if (str == null)
{
lua_pushnil(L);
}
else
{
xlua_pushlstring(L, str, str.Length);
}
}
public static byte[] lua_tobytes(IntPtr L, int index)//[-0, +0, m]
{
if (lua_type(L, index) == LuaTypes.LUA_TSTRING)
{
IntPtr strlen;
IntPtr str = lua_tolstring(L, index, out strlen);
if (str != IntPtr.Zero)
{
int buff_len = strlen.ToInt32();
byte[] buffer = new byte[buff_len];
Marshal.Copy(str, buffer, 0, buff_len);
return buffer;
}
}
return null;
}
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern int luaL_newmetatable(IntPtr L, string meta);//[-0, +1, m]
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int xlua_pgettable(IntPtr L, int idx);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int xlua_psettable(IntPtr L, int idx);
public static void luaL_getmetatable(IntPtr L, string meta)
{
xlua_pushasciistring(L, meta);
lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);
}
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int xluaL_loadbuffer(IntPtr L, byte[] buff, int size, string name);
public static int luaL_loadbuffer(IntPtr L, string buff, string name)//[-0, +1, m]
{
byte[] bytes = Encoding.UTF8.GetBytes(buff);
return xluaL_loadbuffer(L, bytes, bytes.Length, name);
}
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern int xlua_tocsobj_safe(IntPtr L,int obj);//[-0, +0, m]
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern int xlua_tocsobj_fast(IntPtr L,int obj);
public static int lua_error(IntPtr L)
{
xlua_csharp_error(L);
return 0;
}
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool lua_checkstack(IntPtr L,int extra);//[-0, +0, m]
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern int lua_next(IntPtr L,int index);//[-1, +(2|0), e]
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern void lua_pushlightuserdata(IntPtr L, IntPtr udata);
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern IntPtr xlua_tag();
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static extern void luaL_where (IntPtr L, int level);//[-0, +1, m]
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int xlua_tryget_cachedud(IntPtr L, int key, int cache_ref);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern void xlua_pushcsobj(IntPtr L, int key, int meta_ref, bool need_cache, int cache_ref);//[-0, +1, m]
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]//[,,m]
public static extern int gen_obj_indexer(IntPtr L);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]//[,,m]
public static extern int gen_obj_newindexer(IntPtr L);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]//[,,m]
public static extern int gen_cls_indexer(IntPtr L);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]//[,,m]
public static extern int gen_cls_newindexer(IntPtr L);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]//[,,m]
public static extern int get_error_func_ref(IntPtr L);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]//[,,m]
public static extern int load_error_func(IntPtr L, int Ref);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int luaopen_i64lib(IntPtr L);//[,,m]
#if (!UNITY_SWITCH && !UNITY_WEBGL) || UNITY_EDITOR
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int luaopen_socket_core(IntPtr L);//[,,m]
#endif
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern void lua_pushint64(IntPtr L, long n);//[,,m]
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern void lua_pushuint64(IntPtr L, ulong n);//[,,m]
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool lua_isint64(IntPtr L, int idx);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool lua_isuint64(IntPtr L, int idx);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern long lua_toint64(IntPtr L, int idx);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern ulong lua_touint64(IntPtr L, int idx);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern void xlua_push_csharp_function(IntPtr L, IntPtr fn, int n);//[-0,+1,m]
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int xlua_csharp_str_error(IntPtr L, string message);//[-0,+1,m]
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]//[-0,+0,m]
public static extern int xlua_csharp_error(IntPtr L);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_pack_int8_t(IntPtr buff, int offset, byte field);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_unpack_int8_t(IntPtr buff, int offset, out byte field);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_pack_int16_t(IntPtr buff, int offset, short field);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_unpack_int16_t(IntPtr buff, int offset, out short field);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_pack_int32_t(IntPtr buff, int offset, int field);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_unpack_int32_t(IntPtr buff, int offset, out int field);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_pack_int64_t(IntPtr buff, int offset, long field);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_unpack_int64_t(IntPtr buff, int offset, out long field);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_pack_float(IntPtr buff, int offset, float field);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_unpack_float(IntPtr buff, int offset, out float field);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_pack_double(IntPtr buff, int offset, double field);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_unpack_double(IntPtr buff, int offset, out double field);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr xlua_pushstruct(IntPtr L, uint size, int meta_ref);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern void xlua_pushcstable(IntPtr L, uint field_count, int meta_ref);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr lua_touserdata(IntPtr L, int idx);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int xlua_gettypeid(IntPtr L, int idx);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int xlua_get_registry_index();
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int xlua_pgettable_bypath(IntPtr L, int idx, string path);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int xlua_psettable_bypath(IntPtr L, int idx, string path);
//[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
//public static extern void xlua_pushbuffer(IntPtr L, byte[] buff);
//对于Unity,仅浮点组成的struct较多,这几个api用于优化这类struct
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_pack_float2(IntPtr buff, int offset, float f1, float f2);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_unpack_float2(IntPtr buff, int offset, out float f1, out float f2);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_pack_float3(IntPtr buff, int offset, float f1, float f2, float f3);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_unpack_float3(IntPtr buff, int offset, out float f1, out float f2, out float f3);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_pack_float4(IntPtr buff, int offset, float f1, float f2, float f3, float f4);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_unpack_float4(IntPtr buff, int offset, out float f1, out float f2, out float f3, out float f4);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_pack_float5(IntPtr buff, int offset, float f1, float f2, float f3, float f4, float f5);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_unpack_float5(IntPtr buff, int offset, out float f1, out float f2, out float f3, out float f4, out float f5);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_pack_float6(IntPtr buff, int offset, float f1, float f2, float f3, float f4, float f5, float f6);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_unpack_float6(IntPtr buff, int offset, out float f1, out float f2, out float f3, out float f4, out float f5, out float f6);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_pack_decimal(IntPtr buff, int offset, ref decimal dec);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_unpack_decimal(IntPtr buff, int offset, out byte scale, out byte sign, out int hi32, out ulong lo64);
public static bool xlua_is_eq_str(IntPtr L, int index, string str)
{
return xlua_is_eq_str(L, index, str, str.Length);
}
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern bool xlua_is_eq_str(IntPtr L, int index, string str, int str_len);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr xlua_gl(IntPtr L);
#if GEN_CODE_MINIMIZE
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern void xlua_set_csharp_wrapper_caller(IntPtr wrapper);
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern void xlua_push_csharp_wrapper(IntPtr L, int wrapperID);
public static void xlua_set_csharp_wrapper_caller(CSharpWrapperCaller wrapper_caller)
{
#if XLUA_GENERAL || (UNITY_WSA && !UNITY_EDITOR)
GCHandle.Alloc(wrapper);
#endif
xlua_set_csharp_wrapper_caller(Marshal.GetFunctionPointerForDelegate(wrapper_caller));
}
#endif
}
}