11using System . Runtime . InteropServices ;
22
3- using voidp = System . UIntPtr ;
4- using charp = System . IntPtr ;
53using size_t = System . UInt64 ;
64using lua_Number = System . Double ;
75using lua_Integer = System . Int64 ;
@@ -11,7 +9,7 @@ namespace Lua51;
119
1210public struct lua_State
1311{
14- public UIntPtr Handle ;
12+ public nuint Handle ;
1513}
1614
1715public static class Lua
@@ -39,22 +37,22 @@ public struct lua_Debug {
3937 [ StructLayout ( LayoutKind . Sequential , Pack = 1 , CharSet = CharSet . Ansi ) ]
4038 public struct luaL_Reg {
4139 public string name ;
42- public charp func ;
40+ public nint func ;
4341 } ;
4442
4543 [ StructLayout ( LayoutKind . Sequential , Pack = 1 , CharSet = CharSet . Ansi ) ]
4644 public struct luaL_Buffer {
47- public charp p ;
45+ public nint p ;
4846 public int lvl ;
4947 public lua_State L ;
5048 [ MarshalAs ( UnmanagedType . ByValArray , SizeConst = LUAL_BUFFERSIZE ) ]
5149 public sbyte [ ] buffer ;
5250 } ;
5351
5452 public delegate int lua_CFunction ( lua_State L ) ;
55- public delegate charp lua_Reader ( lua_State L , voidp ud , ref size_t sz ) ;
56- public delegate int lua_Writer ( lua_State L , voidp p , size_t sz , voidp ud ) ;
57- public delegate voidp lua_Alloc ( voidp ud , voidp ptr , size_t osize , size_t nsize ) ;
53+ public delegate nint lua_Reader ( lua_State L , nuint ud , ref size_t sz ) ;
54+ public delegate int lua_Writer ( lua_State L , nuint p , size_t sz , nuint ud ) ;
55+ public delegate nuint lua_Alloc ( nuint ud , nuint ptr , size_t osize , size_t nsize ) ;
5856 public delegate void lua_Hook ( lua_State L , lua_Debug ar ) ;
5957
6058 public static unsafe luaL_Reg AsLuaLReg ( string name , delegate * unmanaged< lua_State , int > func ) => new luaL_Reg { name = name , func = ( nint ) func } ;
@@ -145,10 +143,10 @@ public static int lua_upvalueindex(int i)
145143 public const int LUA_MINSTACK = 20 ;
146144
147145 [ DllImport ( DllName , CallingConvention = Convention , EntryPoint = "lua_newstate" ) ]
148- public static extern lua_State _lua_newstate ( charp f , voidp ud ) ;
149- public static lua_State lua_newstate ( lua_Alloc ? f , voidp ud )
146+ public static extern lua_State _lua_newstate ( nint f , nuint ud ) ;
147+ public static lua_State lua_newstate ( lua_Alloc ? f , nuint ud )
150148 {
151- return _lua_newstate ( f == null ? IntPtr . Zero : Marshal . GetFunctionPointerForDelegate < lua_Alloc > ( f ) , ud ) ;
149+ return _lua_newstate ( f == null ? nint . Zero : Marshal . GetFunctionPointerForDelegate < lua_Alloc > ( f ) , ud ) ;
152150 }
153151
154152 [ DllImport ( DllName , CallingConvention = Convention ) ]
@@ -158,11 +156,11 @@ public static lua_State lua_newstate(lua_Alloc? f, voidp ud)
158156 public static extern lua_State lua_newthread ( lua_State L ) ;
159157
160158 [ DllImport ( DllName , CallingConvention = Convention , EntryPoint = "lua_atpanic" ) ]
161- public static extern charp _lua_atpanic ( lua_State L , charp panicf ) ;
159+ public static extern nint _lua_atpanic ( lua_State L , nint panicf ) ;
162160 public static lua_CFunction ? lua_atpanic ( lua_State L , lua_CFunction ? panicf )
163161 {
164- charp panic = _lua_atpanic ( L , panicf == null ? IntPtr . Zero : Marshal . GetFunctionPointerForDelegate < lua_CFunction > ( panicf ) ) ;
165- return panic == IntPtr . Zero ? null : Marshal . GetDelegateForFunctionPointer < lua_CFunction > ( panic ) ;
162+ nint panic = _lua_atpanic ( L , panicf == null ? nint . Zero : Marshal . GetFunctionPointerForDelegate < lua_CFunction > ( panicf ) ) ;
163+ return panic == nint . Zero ? null : Marshal . GetDelegateForFunctionPointer < lua_CFunction > ( panic ) ;
166164 }
167165
168166 [ DllImport ( DllName , CallingConvention = Convention ) ]
@@ -205,7 +203,7 @@ public static lua_State lua_newstate(lua_Alloc? f, voidp ud)
205203 public static extern int lua_type ( lua_State L , int idx ) ;
206204
207205 [ DllImport ( DllName , CallingConvention = Convention , EntryPoint = "lua_typename" ) ]
208- public static extern IntPtr _lua_typename ( lua_State L , int tp ) ;
206+ public static extern nint _lua_typename ( lua_State L , int tp ) ;
209207 public static string ? lua_typename ( lua_State L , int tp )
210208 {
211209 return Marshal . PtrToStringAnsi ( _lua_typename ( L , tp ) ) ;
@@ -230,7 +228,7 @@ public static lua_State lua_newstate(lua_Alloc? f, voidp ud)
230228 public static extern int lua_toboolean ( lua_State L , int idx ) ;
231229
232230 [ DllImport ( DllName , CallingConvention = Convention , EntryPoint = "lua_tolstring" ) ]
233- public static extern IntPtr _lua_tolstring ( lua_State L , int idx , ref size_t len ) ;
231+ public static extern nint _lua_tolstring ( lua_State L , int idx , ref size_t len ) ;
234232 public static string ? lua_tolstring ( lua_State L , int idx , ref size_t len )
235233 {
236234 return Marshal . PtrToStringAnsi ( _lua_tolstring ( L , idx , ref len ) ) ;
@@ -240,21 +238,21 @@ public static lua_State lua_newstate(lua_Alloc? f, voidp ud)
240238 public static extern size_t lua_objlen ( lua_State L , int idx ) ;
241239
242240 [ DllImport ( DllName , CallingConvention = Convention , EntryPoint = "lua_tocfunction" ) ]
243- public static extern charp _lua_tocfunction ( lua_State L , int idx ) ;
241+ public static extern nint _lua_tocfunction ( lua_State L , int idx ) ;
244242 public static lua_CFunction ? lua_tocfunction ( lua_State L , int idx )
245243 {
246- charp ret = _lua_tocfunction ( L , idx ) ;
247- return ret == IntPtr . Zero ? null : Marshal . GetDelegateForFunctionPointer < lua_CFunction > ( ret ) ;
244+ nint ret = _lua_tocfunction ( L , idx ) ;
245+ return ret == nint . Zero ? null : Marshal . GetDelegateForFunctionPointer < lua_CFunction > ( ret ) ;
248246 }
249247
250248 [ DllImport ( DllName , CallingConvention = Convention ) ]
251- public static extern voidp lua_touserdata ( lua_State L , int idx ) ;
249+ public static extern nuint lua_touserdata ( lua_State L , int idx ) ;
252250
253251 [ DllImport ( DllName , CallingConvention = Convention ) ]
254252 public static extern lua_State lua_tothread ( lua_State L , int idx ) ;
255253
256254 [ DllImport ( DllName , CallingConvention = Convention ) ]
257- public static extern voidp lua_topointer ( lua_State L , int idx ) ;
255+ public static extern nuint lua_topointer ( lua_State L , int idx ) ;
258256
259257 [ DllImport ( DllName , CallingConvention = Convention ) ]
260258 public static extern void lua_pushnil ( lua_State L ) ;
@@ -273,28 +271,28 @@ public static lua_State lua_newstate(lua_Alloc? f, voidp ud)
273271
274272 // TODO:
275273 // [DllImport(DllName, CallingConvention = Convention)]
276- // public static extern IntPtr lua_pushvfstring(lua_State L, string fmt, va_list argp);
274+ // public static extern nint lua_pushvfstring(lua_State L, string fmt, va_list argp);
277275
278276 // TODO:
279277 // [DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_pushfstring")]
280- // public static extern IntPtr _lua_pushfstring(lua_State L, string fmt, params string[] args);
278+ // public static extern nint _lua_pushfstring(lua_State L, string fmt, params string[] args);
281279 // public static string? lua_pushfstring(lua_State L, string fmt, params string[] args)
282280 // {
283281 // return Marshal.PtrToStringAnsi(_lua_pushfstring(L, fmt, args));
284282 // }
285283
286284 [ DllImport ( DllName , CallingConvention = Convention , EntryPoint = "lua_pushcclosure" ) ]
287- public static extern void _lua_pushcclosure ( lua_State L , charp fn , int n ) ;
285+ public static extern void _lua_pushcclosure ( lua_State L , nint fn , int n ) ;
288286 public static void lua_pushcclosure ( lua_State L , lua_CFunction ? fn , int n )
289287 {
290- _lua_pushcclosure ( L , fn == null ? IntPtr . Zero : Marshal . GetFunctionPointerForDelegate ( fn ) , n ) ;
288+ _lua_pushcclosure ( L , fn == null ? nint . Zero : Marshal . GetFunctionPointerForDelegate ( fn ) , n ) ;
291289 }
292290
293291 [ DllImport ( DllName , CallingConvention = Convention ) ]
294292 public static extern void lua_pushboolean ( lua_State L , int b ) ;
295293
296294 [ DllImport ( DllName , CallingConvention = Convention ) ]
297- public static extern void lua_pushlightuserdata ( lua_State L , voidp p ) ;
295+ public static extern void lua_pushlightuserdata ( lua_State L , nuint p ) ;
298296
299297 [ DllImport ( DllName , CallingConvention = Convention ) ]
300298 public static extern int lua_pushthread ( lua_State L ) ;
@@ -315,7 +313,7 @@ public static void lua_pushcclosure(lua_State L, lua_CFunction? fn, int n)
315313 public static extern void lua_createtable ( lua_State L , int narr , int nrec ) ;
316314
317315 [ DllImport ( DllName , CallingConvention = Convention ) ]
318- public static extern voidp lua_newuserdata ( lua_State L , size_t sz ) ;
316+ public static extern nuint lua_newuserdata ( lua_State L , size_t sz ) ;
319317
320318 [ DllImport ( DllName , CallingConvention = Convention ) ]
321319 public static extern int lua_getmetatable ( lua_State L , int objindex ) ;
@@ -348,24 +346,24 @@ public static void lua_pushcclosure(lua_State L, lua_CFunction? fn, int n)
348346 public static extern int lua_pcall ( lua_State L , int nargs , int nresults , int errfunc ) ;
349347
350348 [ DllImport ( DllName , CallingConvention = Convention , EntryPoint = "lua_cpcall" ) ]
351- public static extern int _lua_cpcall ( lua_State L , charp func , voidp ud ) ;
352- public static int lua_cpcall ( lua_State L , lua_CFunction ? func , voidp ud )
349+ public static extern int _lua_cpcall ( lua_State L , nint func , nuint ud ) ;
350+ public static int lua_cpcall ( lua_State L , lua_CFunction ? func , nuint ud )
353351 {
354- return _lua_cpcall ( L , func == null ? IntPtr . Zero : Marshal . GetFunctionPointerForDelegate < lua_CFunction > ( func ) , ud ) ;
352+ return _lua_cpcall ( L , func == null ? nint . Zero : Marshal . GetFunctionPointerForDelegate < lua_CFunction > ( func ) , ud ) ;
355353 }
356354
357355 [ DllImport ( DllName , CallingConvention = Convention , EntryPoint = "lua_load" ) ]
358- public static extern int _lua_load ( lua_State L , charp reader , voidp dt , string chunkname ) ;
359- public static int lua_load ( lua_State L , lua_Reader ? reader , voidp dt , string chunkname )
356+ public static extern int _lua_load ( lua_State L , nint reader , nuint dt , string chunkname ) ;
357+ public static int lua_load ( lua_State L , lua_Reader ? reader , nuint dt , string chunkname )
360358 {
361- return _lua_load ( L , reader == null ? IntPtr . Zero : Marshal . GetFunctionPointerForDelegate < lua_Reader > ( reader ) , dt , chunkname ) ;
359+ return _lua_load ( L , reader == null ? nint . Zero : Marshal . GetFunctionPointerForDelegate < lua_Reader > ( reader ) , dt , chunkname ) ;
362360 }
363361
364362 [ DllImport ( DllName , CallingConvention = Convention , EntryPoint = "lua_dump" ) ]
365- public static extern int _lua_dump ( lua_State L , charp writer , voidp data ) ;
366- public static int lua_dump ( lua_State L , lua_Writer ? writer , voidp data )
363+ public static extern int _lua_dump ( lua_State L , nint writer , nuint data ) ;
364+ public static int lua_dump ( lua_State L , lua_Writer ? writer , nuint data )
367365 {
368- return _lua_dump ( L , writer == null ? IntPtr . Zero : Marshal . GetFunctionPointerForDelegate < lua_Writer > ( writer ) , data ) ;
366+ return _lua_dump ( L , writer == null ? nint . Zero : Marshal . GetFunctionPointerForDelegate < lua_Writer > ( writer ) , data ) ;
369367 }
370368
371369 [ DllImport ( DllName , CallingConvention = Convention ) ]
@@ -399,13 +397,13 @@ public static int lua_dump(lua_State L, lua_Writer? writer, voidp data)
399397 public static extern void lua_concat ( lua_State L , int n ) ;
400398
401399 [ DllImport ( DllName , CallingConvention = Convention ) ]
402- public static extern lua_Alloc lua_getallocf ( lua_State L , out voidp ud ) ;
400+ public static extern lua_Alloc lua_getallocf ( lua_State L , out nuint ud ) ;
403401
404402 [ DllImport ( DllName , CallingConvention = Convention , EntryPoint = "lua_setallocf" ) ]
405- public static extern void _lua_setallocf ( lua_State L , charp f , voidp ud ) ;
406- public static void lua_setallocf ( lua_State L , lua_Alloc ? f , voidp ud )
403+ public static extern void _lua_setallocf ( lua_State L , nint f , nuint ud ) ;
404+ public static void lua_setallocf ( lua_State L , lua_Alloc ? f , nuint ud )
407405 {
408- _lua_setallocf ( L , f == null ? IntPtr . Zero : Marshal . GetFunctionPointerForDelegate < lua_Alloc > ( f ) , ud ) ;
406+ _lua_setallocf ( L , f == null ? nint . Zero : Marshal . GetFunctionPointerForDelegate < lua_Alloc > ( f ) , ud ) ;
409407 }
410408
411409 public static void lua_pop ( lua_State L , int n )
@@ -531,46 +529,46 @@ public static int lua_getgccount(lua_State L)
531529 public static extern int lua_getinfo ( lua_State L , string what , lua_Debug ar ) ;
532530
533531 [ DllImport ( DllName , CallingConvention = Convention , EntryPoint = "lua_getlocal" ) ]
534- public static extern IntPtr _lua_getlocal ( lua_State L , lua_Debug ar , int n ) ;
532+ public static extern nint _lua_getlocal ( lua_State L , lua_Debug ar , int n ) ;
535533 public static string ? lua_getlocal ( lua_State L , lua_Debug ar , int n )
536534 {
537535 return Marshal . PtrToStringAnsi ( _lua_getlocal ( L , ar , n ) ) ;
538536 }
539537
540538 [ DllImport ( DllName , CallingConvention = Convention , EntryPoint = "lua_setlocal" ) ]
541- public static extern IntPtr _lua_setlocal ( lua_State L , lua_Debug ar , int n ) ;
539+ public static extern nint _lua_setlocal ( lua_State L , lua_Debug ar , int n ) ;
542540 public static string ? lua_setlocal ( lua_State L , lua_Debug ar , int n )
543541 {
544542 return Marshal . PtrToStringAnsi ( _lua_setlocal ( L , ar , n ) ) ;
545543 }
546544
547545 [ DllImport ( DllName , CallingConvention = Convention , EntryPoint = "lua_getupvalue" ) ]
548- public static extern IntPtr _lua_getupvalue ( lua_State L , int funcindex , int n ) ;
546+ public static extern nint _lua_getupvalue ( lua_State L , int funcindex , int n ) ;
549547 public static string ? lua_getupvalue ( lua_State L , int funcindex , int n )
550548 {
551549 return Marshal . PtrToStringAnsi ( _lua_getupvalue ( L , funcindex , n ) ) ;
552550 }
553551
554552 [ DllImport ( DllName , CallingConvention = Convention , EntryPoint = "lua_setupvalue" ) ]
555- public static extern IntPtr _lua_setupvalue ( lua_State L , int funcindex , int n ) ;
553+ public static extern nint _lua_setupvalue ( lua_State L , int funcindex , int n ) ;
556554 public static string ? lua_setupvalue ( lua_State L , int funcindex , int n )
557555 {
558556 return Marshal . PtrToStringAnsi ( _lua_setupvalue ( L , funcindex , n ) ) ;
559557 }
560558
561559 [ DllImport ( DllName , CallingConvention = Convention , EntryPoint = "lua_sethook" ) ]
562- public static extern int _lua_sethook ( lua_State L , charp func , int mask , int count ) ;
560+ public static extern int _lua_sethook ( lua_State L , nint func , int mask , int count ) ;
563561 public static int lua_sethook ( lua_State L , lua_Hook ? func , int mask , int count )
564562 {
565- return _lua_sethook ( L , func == null ? IntPtr . Zero : Marshal . GetFunctionPointerForDelegate < lua_Hook > ( func ) , mask , count ) ;
563+ return _lua_sethook ( L , func == null ? nint . Zero : Marshal . GetFunctionPointerForDelegate < lua_Hook > ( func ) , mask , count ) ;
566564 }
567565
568566 [ DllImport ( DllName , CallingConvention = Convention , EntryPoint = "lua_gethook" ) ]
569- public static extern charp _lua_gethook ( lua_State L ) ;
567+ public static extern nint _lua_gethook ( lua_State L ) ;
570568 public static lua_Hook ? lua_gethook ( lua_State L )
571569 {
572- charp ret = _lua_gethook ( L ) ;
573- return ret == IntPtr . Zero ? null : Marshal . GetDelegateForFunctionPointer < lua_Hook > ( ret ) ;
570+ nint ret = _lua_gethook ( L ) ;
571+ return ret == nint . Zero ? null : Marshal . GetDelegateForFunctionPointer < lua_Hook > ( ret ) ;
574572 }
575573
576574 [ DllImport ( DllName , CallingConvention = Convention ) ]
@@ -610,14 +608,14 @@ public static void luaL_setn(lua_State L, int i, int j)
610608 public static extern int luaL_argerror ( lua_State L , int numarg , string extramsg ) ;
611609
612610 [ DllImport ( DllName , CallingConvention = Convention , EntryPoint = "luaL_checklstring" ) ]
613- public static extern IntPtr _luaL_checklstring ( lua_State L , int numArg , ref size_t l ) ;
611+ public static extern nint _luaL_checklstring ( lua_State L , int numArg , ref size_t l ) ;
614612 public static string ? luaL_checklstring ( lua_State L , int numArg , ref size_t l )
615613 {
616614 return Marshal . PtrToStringAnsi ( _luaL_checklstring ( L , numArg , ref l ) ) ;
617615 }
618616
619617 [ DllImport ( DllName , CallingConvention = Convention , EntryPoint = "luaL_optlstring" ) ]
620- public static extern IntPtr _luaL_optlstring ( lua_State L , int numArg , string def , ref size_t l ) ;
618+ public static extern nint _luaL_optlstring ( lua_State L , int numArg , string def , ref size_t l ) ;
621619 public static string ? luaL_optlstring ( lua_State L , int numArg , string def , ref size_t l )
622620 {
623621 return Marshal . PtrToStringAnsi ( _luaL_optlstring ( L , numArg , def , ref l ) ) ;
@@ -648,7 +646,7 @@ public static void luaL_setn(lua_State L, int i, int j)
648646 public static extern int luaL_newmetatable ( lua_State L , string tname ) ;
649647
650648 [ DllImport ( DllName , CallingConvention = Convention ) ]
651- public static extern voidp luaL_checkudata ( lua_State L , int ud , string tname ) ;
649+ public static extern nuint luaL_checkudata ( lua_State L , int ud , string tname ) ;
652650
653651 [ DllImport ( DllName , CallingConvention = Convention ) ]
654652 public static extern void luaL_where ( lua_State L , int lvl ) ;
@@ -679,14 +677,14 @@ public static void luaL_setn(lua_State L, int i, int j)
679677 public static extern lua_State luaL_newstate ( ) ;
680678
681679 [ DllImport ( DllName , CallingConvention = Convention , EntryPoint = "luaL_gsub" ) ]
682- public static extern IntPtr _luaL_gsub ( lua_State L , string s , string p , string r ) ;
680+ public static extern nint _luaL_gsub ( lua_State L , string s , string p , string r ) ;
683681 public static string ? luaL_gsub ( lua_State L , string s , string p , string r )
684682 {
685683 return Marshal . PtrToStringAnsi ( _luaL_gsub ( L , s , p , r ) ) ;
686684 }
687685
688686 [ DllImport ( DllName , CallingConvention = Convention , EntryPoint = "luaL_findtable" ) ]
689- public static extern IntPtr _luaL_findtable ( lua_State L , int idx , string fname , int szhint ) ;
687+ public static extern nint _luaL_findtable ( lua_State L , int idx , string fname , int szhint ) ;
690688 public static string ? luaL_findtable ( lua_State L , int idx , string fname , int szhint )
691689 {
692690 return Marshal . PtrToStringAnsi ( _luaL_findtable ( L , idx , fname , szhint ) ) ;
@@ -785,7 +783,7 @@ public static void luaL_addsize(luaL_Buffer B, int n)
785783 public static extern void luaL_buffinit ( lua_State L , luaL_Buffer B ) ;
786784
787785 [ DllImport ( DllName , CallingConvention = Convention ) ]
788- public static extern charp luaL_prepbuffer ( luaL_Buffer B ) ;
786+ public static extern nint luaL_prepbuffer ( luaL_Buffer B ) ;
789787
790788 [ DllImport ( DllName , CallingConvention = Convention ) ]
791789 public static extern void luaL_addlstring ( luaL_Buffer B , string s , size_t l ) ;
0 commit comments