Skip to content

Commit dde367b

Browse files
committed
Clean up code
1 parent 3d42d68 commit dde367b

File tree

5 files changed

+111
-111
lines changed

5 files changed

+111
-111
lines changed

src/Lua51.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public struct luaL_Buffer {
6767
public delegate nuint lua_Alloc(nuint ud, nuint ptr, size_t osize, size_t nsize);
6868
public delegate void lua_Hook(lua_State L, lua_Debug ar);
6969

70-
public static unsafe luaL_Reg AsLuaLReg(string name, delegate*unmanaged<lua_State, int> func) => new luaL_Reg { name = name, func = (nint) func };
70+
public static unsafe luaL_Reg AsLuaLReg(string name, delegate*unmanaged<lua_State, int> func) => new() { name = name, func = (nint) func };
7171

7272
public const string LUA_PATH = "LUA_PATH";
7373
public const string LUA_CPATH = "LUA_CPATH";
@@ -158,7 +158,7 @@ public static int lua_upvalueindex(int i)
158158
private static extern lua_State _lua_newstate(nint f, nuint ud);
159159
public static lua_State lua_newstate(lua_Alloc? f, nuint ud)
160160
{
161-
return _lua_newstate(f == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate<lua_Alloc>(f), ud);
161+
return _lua_newstate(f == null ? 0 : Marshal.GetFunctionPointerForDelegate(f), ud);
162162
}
163163

164164
[DllImport(DllName, CallingConvention = Convention)]
@@ -171,8 +171,8 @@ public static lua_State lua_newstate(lua_Alloc? f, nuint ud)
171171
private static extern nint _lua_atpanic(lua_State L, nint panicf);
172172
public static lua_CFunction? lua_atpanic(lua_State L, lua_CFunction? panicf)
173173
{
174-
nint panic = _lua_atpanic(L, panicf == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate<lua_CFunction>(panicf));
175-
return panic == ((nint) 0) ? null : Marshal.GetDelegateForFunctionPointer<lua_CFunction>(panic);
174+
nint panic = _lua_atpanic(L, panicf == null ? 0 : Marshal.GetFunctionPointerForDelegate(panicf));
175+
return panic == 0 ? null : Marshal.GetDelegateForFunctionPointer<lua_CFunction>(panic);
176176
}
177177

178178
[DllImport(DllName, CallingConvention = Convention)]
@@ -254,7 +254,7 @@ public static lua_State lua_newstate(lua_Alloc? f, nuint ud)
254254
public static lua_CFunction? lua_tocfunction(lua_State L, int idx)
255255
{
256256
nint ret = _lua_tocfunction(L, idx);
257-
return ret == ((nint) 0) ? null : Marshal.GetDelegateForFunctionPointer<lua_CFunction>(ret);
257+
return ret == 0 ? null : Marshal.GetDelegateForFunctionPointer<lua_CFunction>(ret);
258258
}
259259

260260
[DllImport(DllName, CallingConvention = Convention)]
@@ -297,7 +297,7 @@ public static lua_State lua_newstate(lua_Alloc? f, nuint ud)
297297
private static extern void _lua_pushcclosure(lua_State L, nint fn, int n);
298298
public static void lua_pushcclosure(lua_State L, lua_CFunction? fn, int n)
299299
{
300-
_lua_pushcclosure(L, fn == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate(fn), n);
300+
_lua_pushcclosure(L, fn == null ? 0 : Marshal.GetFunctionPointerForDelegate(fn), n);
301301
}
302302

303303
[DllImport(DllName, CallingConvention = Convention)]
@@ -361,21 +361,21 @@ public static void lua_pushcclosure(lua_State L, lua_CFunction? fn, int n)
361361
private static extern int _lua_cpcall(lua_State L, nint func, nuint ud);
362362
public static int lua_cpcall(lua_State L, lua_CFunction? func, nuint ud)
363363
{
364-
return _lua_cpcall(L, func == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate<lua_CFunction>(func), ud);
364+
return _lua_cpcall(L, func == null ? 0 : Marshal.GetFunctionPointerForDelegate(func), ud);
365365
}
366366

367367
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_load")]
368368
private static extern int _lua_load(lua_State L, nint reader, nuint dt, string chunkname);
369369
public static int lua_load(lua_State L, lua_Reader? reader, nuint dt, string chunkname)
370370
{
371-
return _lua_load(L, reader == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate<lua_Reader>(reader), dt, chunkname);
371+
return _lua_load(L, reader == null ? 0 : Marshal.GetFunctionPointerForDelegate(reader), dt, chunkname);
372372
}
373373

374374
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_dump")]
375375
private static extern int _lua_dump(lua_State L, nint writer, nuint data);
376376
public static int lua_dump(lua_State L, lua_Writer? writer, nuint data)
377377
{
378-
return _lua_dump(L, writer == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate<lua_Writer>(writer), data);
378+
return _lua_dump(L, writer == null ? 0 : Marshal.GetFunctionPointerForDelegate(writer), data);
379379
}
380380

381381
[DllImport(DllName, CallingConvention = Convention)]
@@ -415,12 +415,12 @@ public static int lua_dump(lua_State L, lua_Writer? writer, nuint data)
415415
private static extern void _lua_setallocf(lua_State L, nint f, nuint ud);
416416
public static void lua_setallocf(lua_State L, lua_Alloc? f, nuint ud)
417417
{
418-
_lua_setallocf(L, f == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate<lua_Alloc>(f), ud);
418+
_lua_setallocf(L, f == null ? 0 : Marshal.GetFunctionPointerForDelegate(f), ud);
419419
}
420420

421421
public static void lua_pop(lua_State L, int n)
422422
{
423-
lua_settop(L, -(n)-1);
423+
lua_settop(L, -n-1);
424424
}
425425

426426
public static void lua_newtable(lua_State L)
@@ -529,10 +529,10 @@ public static int lua_getgccount(lua_State L)
529529
public const int LUA_HOOKCOUNT = 3;
530530
public const int LUA_HOOKTAILRET = 4;
531531

532-
public const int LUA_MASKCALL = (1 << LUA_HOOKCALL);
533-
public const int LUA_MASKRET = (1 << LUA_HOOKRET);
534-
public const int LUA_MASKLINE = (1 << LUA_HOOKLINE);
535-
public const int LUA_MASKCOUNT = (1 << LUA_HOOKCOUNT);
532+
public const int LUA_MASKCALL = 1 << LUA_HOOKCALL;
533+
public const int LUA_MASKRET = 1 << LUA_HOOKRET;
534+
public const int LUA_MASKLINE = 1 << LUA_HOOKLINE;
535+
public const int LUA_MASKCOUNT = 1 << LUA_HOOKCOUNT;
536536

537537
[DllImport(DllName, CallingConvention = Convention)]
538538
public static extern int lua_getstack(lua_State L, int level, lua_Debug ar);
@@ -572,15 +572,15 @@ public static int lua_getgccount(lua_State L)
572572
private static extern int _lua_sethook(lua_State L, nint func, int mask, int count);
573573
public static int lua_sethook(lua_State L, lua_Hook? func, int mask, int count)
574574
{
575-
return _lua_sethook(L, func == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate<lua_Hook>(func), mask, count);
575+
return _lua_sethook(L, func == null ? 0 : Marshal.GetFunctionPointerForDelegate(func), mask, count);
576576
}
577577

578578
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_gethook")]
579579
private static extern nint _lua_gethook(lua_State L);
580580
public static lua_Hook? lua_gethook(lua_State L)
581581
{
582582
nint ret = _lua_gethook(L);
583-
return ret == ((nint) 0) ? null : Marshal.GetDelegateForFunctionPointer<lua_Hook>(ret);
583+
return ret == 0 ? null : Marshal.GetDelegateForFunctionPointer<lua_Hook>(ret);
584584
}
585585

586586
[DllImport(DllName, CallingConvention = Convention)]
@@ -732,12 +732,12 @@ public static int luaL_optint(lua_State L, int n, lua_Integer d)
732732

733733
public static long luaL_checklong(lua_State L, int n)
734734
{
735-
return (long) luaL_checkinteger(L, n);
735+
return luaL_checkinteger(L, n);
736736
}
737737

738738
public static long luaL_optlong(lua_State L, int n, lua_Integer d)
739739
{
740-
return (long) luaL_optinteger(L, n, d);
740+
return luaL_optinteger(L, n, d);
741741
}
742742

743743
public static string? luaL_typename(lua_State L, int i)

src/Lua52.cs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public struct luaL_Buffer {
7272
public delegate nuint lua_Alloc(nuint ud, nuint ptr, size_t osize, size_t nsize);
7373
public delegate void lua_Hook(lua_State L, lua_Debug ar);
7474

75-
public static unsafe luaL_Reg AsLuaLReg(string name, delegate*unmanaged<lua_State, int> func) => new luaL_Reg { name = name, func = (nint) func };
75+
public static unsafe luaL_Reg AsLuaLReg(string name, delegate*unmanaged<lua_State, int> func) => new() { name = name, func = (nint) func };
7676

7777
public const string LUA_LDIR = "!\\lua\\";
7878
public const string LUA_CDIR = "!\\";
@@ -125,7 +125,7 @@ public static int lua_lessthan(lua_State L, int idx1, int idx2)
125125

126126
public const int LUAI_MAXSTACK = 1000000;
127127

128-
public const int LUAI_FIRSTPSEUDOIDX = (-LUAI_MAXSTACK - 1000);
128+
public const int LUAI_FIRSTPSEUDOIDX = -LUAI_MAXSTACK - 1000;
129129

130130
public const int LUAL_BUFFERSIZE = 512;
131131

@@ -181,7 +181,7 @@ public static int lua_upvalueindex(int i)
181181
private static extern lua_State _lua_newstate(nint f, nuint ud);
182182
public static lua_State lua_newstate(lua_Alloc? f, nuint ud)
183183
{
184-
return _lua_newstate(f == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate<lua_Alloc>(f), ud);
184+
return _lua_newstate(f == null ? 0 : Marshal.GetFunctionPointerForDelegate(f), ud);
185185
}
186186

187187
[DllImport(DllName, CallingConvention = Convention)]
@@ -194,16 +194,16 @@ public static lua_State lua_newstate(lua_Alloc? f, nuint ud)
194194
private static extern nint _lua_atpanic(lua_State L, nint panicf);
195195
public static lua_CFunction? lua_atpanic(lua_State L, lua_CFunction? panicf)
196196
{
197-
nint panic = _lua_atpanic(L, panicf == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate<lua_CFunction>(panicf));
198-
return panic == ((nint) 0) ? null : Marshal.GetDelegateForFunctionPointer<lua_CFunction>(panic);
197+
nint panic = _lua_atpanic(L, panicf == null ? 0 : Marshal.GetFunctionPointerForDelegate(panicf));
198+
return panic == 0 ? null : Marshal.GetDelegateForFunctionPointer<lua_CFunction>(panic);
199199
}
200200

201201
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_version")]
202202
private static extern nint _lua_version(lua_State L);
203203
public static double lua_version(lua_State L)
204204
{
205205
nint mem = _lua_version(L);
206-
if (mem == ((nint) 0))
206+
if (mem == 0)
207207
return 0;
208208
byte[] arr = new byte[8];
209209
for (int i=0; i<arr.Length; i++)
@@ -290,7 +290,7 @@ public static double lua_version(lua_State L)
290290
public static lua_CFunction? lua_tocfunction(lua_State L, int idx)
291291
{
292292
nint ret = _lua_tocfunction(L, idx);
293-
return ret == ((nint) 0) ? null : Marshal.GetDelegateForFunctionPointer<lua_CFunction>(ret);
293+
return ret == 0 ? null : Marshal.GetDelegateForFunctionPointer<lua_CFunction>(ret);
294294
}
295295

296296
[DllImport(DllName, CallingConvention = Convention)]
@@ -365,7 +365,7 @@ public static double lua_version(lua_State L)
365365
private static extern void _lua_pushcclosure(lua_State L, nint fn, int n);
366366
public static void lua_pushcclosure(lua_State L, lua_CFunction? fn, int n)
367367
{
368-
_lua_pushcclosure(L, fn == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate(fn), n);
368+
_lua_pushcclosure(L, fn == null ? 0 : Marshal.GetFunctionPointerForDelegate(fn), n);
369369
}
370370

371371
[DllImport(DllName, CallingConvention = Convention)]
@@ -435,7 +435,7 @@ public static void lua_pushcclosure(lua_State L, lua_CFunction? fn, int n)
435435
private static extern void _lua_callk(lua_State L, int nargs, int nresults, int ctx, nint k);
436436
public static void lua_callk(lua_State L, int nargs, int nresults, int ctx, lua_CFunction? k)
437437
{
438-
_lua_callk(L, nargs, nresults, ctx, k == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate<lua_CFunction>(k));
438+
_lua_callk(L, nargs, nresults, ctx, k == null ? 0 : Marshal.GetFunctionPointerForDelegate(k));
439439
}
440440

441441
public static void lua_call(lua_State L, int n, int r)
@@ -450,7 +450,7 @@ public static void lua_call(lua_State L, int n, int r)
450450
private static extern int _lua_pcallk(lua_State L, int nargs, int nresults, int errfunc, int ctx, nint k);
451451
public static int lua_pcallk(lua_State L, int nargs, int nresults, int errfunc, int ctx, lua_CFunction? k)
452452
{
453-
return _lua_pcallk(L, nargs, nresults, errfunc, ctx, k == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate<lua_CFunction>(k));
453+
return _lua_pcallk(L, nargs, nresults, errfunc, ctx, k == null ? 0 : Marshal.GetFunctionPointerForDelegate(k));
454454
}
455455

456456
public static int lua_pcall(lua_State L, int n, int r, int f)
@@ -462,21 +462,21 @@ public static int lua_pcall(lua_State L, int n, int r, int f)
462462
private static extern int _lua_load(lua_State L, nint reader, nuint dt, string chunkname, string? mode);
463463
public static int lua_load(lua_State L, lua_Reader? reader, nuint dt, string chunkname, string? mode)
464464
{
465-
return _lua_load(L, reader == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate<lua_Reader>(reader), dt, chunkname, mode);
465+
return _lua_load(L, reader == null ? 0 : Marshal.GetFunctionPointerForDelegate(reader), dt, chunkname, mode);
466466
}
467467

468468
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_dump")]
469469
private static extern int _lua_dump(lua_State L, nint writer, nuint data);
470470
public static int lua_dump(lua_State L, lua_Writer? writer, nuint data)
471471
{
472-
return _lua_dump(L, writer == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate<lua_Writer>(writer), data);
472+
return _lua_dump(L, writer == null ? 0 : Marshal.GetFunctionPointerForDelegate(writer), data);
473473
}
474474

475475
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_yieldk")]
476476
private static extern int _lua_yieldk(lua_State L, int nresults, int ctx, nint k);
477477
public static int lua_yieldk(lua_State L, int nresults, int ctx, lua_CFunction? k)
478478
{
479-
return _lua_yieldk(L, nresults, ctx, k == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate<lua_CFunction>(k));
479+
return _lua_yieldk(L, nresults, ctx, k == null ? 0 : Marshal.GetFunctionPointerForDelegate(k));
480480
}
481481

482482
public static int lua_yield(lua_State L, int n)
@@ -525,7 +525,7 @@ public static int lua_yield(lua_State L, int n)
525525
private static extern void _lua_setallocf(lua_State L, nint f, nuint ud);
526526
public static void lua_setallocf(lua_State L, lua_Alloc? f, nuint ud)
527527
{
528-
_lua_setallocf(L, f == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate<lua_Alloc>(f), ud);
528+
_lua_setallocf(L, f == null ? 0 : Marshal.GetFunctionPointerForDelegate(f), ud);
529529
}
530530

531531
public static double lua_tonumber(lua_State L, int i)
@@ -548,7 +548,7 @@ public static ulong lua_tounsigned(lua_State L, int i)
548548

549549
public static void lua_pop(lua_State L, int n)
550550
{
551-
lua_settop(L, -(n)-1);
551+
lua_settop(L, -n-1);
552552
}
553553

554554
public static void lua_newtable(lua_State L)
@@ -629,10 +629,10 @@ public static void lua_pushglobaltable(lua_State L)
629629
public const int LUA_HOOKCOUNT = 3;
630630
public const int LUA_HOOKTAILCALL = 4;
631631

632-
public const int LUA_MASKCALL = (1 << LUA_HOOKCALL);
633-
public const int LUA_MASKRET = (1 << LUA_HOOKRET);
634-
public const int LUA_MASKLINE = (1 << LUA_HOOKLINE);
635-
public const int LUA_MASKCOUNT = (1 << LUA_HOOKCOUNT);
632+
public const int LUA_MASKCALL = 1 << LUA_HOOKCALL;
633+
public const int LUA_MASKRET = 1 << LUA_HOOKRET;
634+
public const int LUA_MASKLINE = 1 << LUA_HOOKLINE;
635+
public const int LUA_MASKCOUNT = 1 << LUA_HOOKCOUNT;
636636

637637
[DllImport(DllName, CallingConvention = Convention)]
638638
public static extern int lua_getstack(lua_State L, int level, lua_Debug ar);
@@ -678,15 +678,15 @@ public static void lua_pushglobaltable(lua_State L)
678678
private static extern int _lua_sethook(lua_State L, nint func, int mask, int count);
679679
public static int lua_sethook(lua_State L, lua_Hook? func, int mask, int count)
680680
{
681-
return _lua_sethook(L, func == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate<lua_Hook>(func), mask, count);
681+
return _lua_sethook(L, func == null ? 0 : Marshal.GetFunctionPointerForDelegate(func), mask, count);
682682
}
683683

684684
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_gethook")]
685685
private static extern nint _lua_gethook(lua_State L);
686686
public static lua_Hook? lua_gethook(lua_State L)
687687
{
688688
nint ret = _lua_gethook(L);
689-
return ret == ((nint) 0) ? null : Marshal.GetDelegateForFunctionPointer<lua_Hook>(ret);
689+
return ret == 0 ? null : Marshal.GetDelegateForFunctionPointer<lua_Hook>(ret);
690690
}
691691

692692
[DllImport(DllName, CallingConvention = Convention)]
@@ -839,7 +839,7 @@ public static int luaL_loadfile(lua_State L, string f)
839839
private static extern void _luaL_requiref(lua_State L, string modname, nint openf, int glb);
840840
public static void luaL_requiref(lua_State L, string modname, lua_CFunction? openf, int glb)
841841
{
842-
_luaL_requiref(L, modname, openf == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate<lua_CFunction>(openf), glb);
842+
_luaL_requiref(L, modname, openf == null ? 0 : Marshal.GetFunctionPointerForDelegate(openf), glb);
843843
}
844844

845845
public static void luaL_newlibtable(lua_State L, luaL_Reg[] l)
@@ -883,12 +883,12 @@ public static int luaL_optint(lua_State L, int n, lua_Integer d)
883883

884884
public static long luaL_checklong(lua_State L, int n)
885885
{
886-
return (long) luaL_checkinteger(L, n);
886+
return luaL_checkinteger(L, n);
887887
}
888888

889889
public static long luaL_optlong(lua_State L, int n, lua_Integer d)
890890
{
891-
return (long) luaL_optinteger(L, n, d);
891+
return luaL_optinteger(L, n, d);
892892
}
893893

894894
public static string? luaL_typename(lua_State L, int i)

0 commit comments

Comments
 (0)