Skip to content

Commit 5fe5f89

Browse files
committed
Did the following:
- Added a CONTRIBUTING.md - Removed outdated information from README.md - Made _ prefixed lua function shims private
1 parent 43f7ccf commit 5fe5f89

File tree

7 files changed

+172
-141
lines changed

7 files changed

+172
-141
lines changed

CONTRIBUTING.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## How to Contribute
2+
3+
1. Follow the code style
4+
```C#
5+
if ()
6+
{
7+
8+
}
9+
10+
try
11+
{
12+
13+
}
14+
catch (...)
15+
{
16+
17+
}
18+
19+
if ()
20+
return;
21+
22+
for (int i = 0; i<=1; i++)
23+
{
24+
25+
}
26+
27+
while (...)
28+
{
29+
30+
}
31+
32+
private int _name;
33+
public int Name;
34+
public int Name { get; private set; }
35+
36+
public void Example(int argName)
37+
{
38+
39+
}
40+
```
41+
42+
2. Push changes to a new local branch to the 'dev' branch. ('contributor-feature' -> 'dev')
43+
3. You are encouraged to start a PR early so we can spy on what you are working on!
44+
4. Versions should not be bumped at all
45+
5. gitignore is free game add anything that fits

README.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,13 @@ No DLL has to be built for this library as its included for you.
1515

1616
Custom DLLs are supported as long as they don't change any call arguments or return values.
1717

18-
To build Lua, get the Lua source from [Lua.org](https://www.lua.org/download.html) or [LuaJIT](https://luajit.org/download.html).
19-
```bat
20-
make -j24
21-
```
22-
Then rename the dll to the above convention.
23-
2418
# Design Considerations / Usage
2519

2620
Your delegates you pass to functions such as `lua_pushcfunction(...)` should be static.
2721
If you do not use static, then the lifetime of your functions should exceed the lifetime of the Lua the final Lua context you create during the course of the program.
2822
Do not use lambdas.
2923
C# is liable to GC your delegates otherwise.
3024

31-
There are functions prefixed with an underscore.
32-
These functions denote raw DllImported functions.
33-
The reason these exist is because some functions needed a shim function for it to work properly/sanely, i.e. marshaling.
34-
You can write your own functions against those.
35-
For example, if you want a function like lua_pcall but not have to specify an error handler offset you can invoke _lua_pcall(...) in a util class (all functions are static).
36-
This library does not use unsafe, however, going unsafe should work perfectly.
37-
If you are just here to use the library, you can get by without having to worry about the underscore prefixed functions.
38-
3925
# Examples
4026

4127
Example Usage Lua5.4.4:

src/Lua51.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public static int lua_upvalueindex(int i)
143143
public const int LUA_MINSTACK = 20;
144144

145145
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_newstate")]
146-
public static extern lua_State _lua_newstate(nint f, nuint ud);
146+
private static extern lua_State _lua_newstate(nint f, nuint ud);
147147
public static lua_State lua_newstate(lua_Alloc? f, nuint ud)
148148
{
149149
return _lua_newstate(f == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate<lua_Alloc>(f), ud);
@@ -156,7 +156,7 @@ public static lua_State lua_newstate(lua_Alloc? f, nuint ud)
156156
public static extern lua_State lua_newthread(lua_State L);
157157

158158
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_atpanic")]
159-
public static extern nint _lua_atpanic(lua_State L, nint panicf);
159+
private static extern nint _lua_atpanic(lua_State L, nint panicf);
160160
public static lua_CFunction? lua_atpanic(lua_State L, lua_CFunction? panicf)
161161
{
162162
nint panic = _lua_atpanic(L, panicf == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate<lua_CFunction>(panicf));
@@ -203,7 +203,7 @@ public static lua_State lua_newstate(lua_Alloc? f, nuint ud)
203203
public static extern int lua_type(lua_State L, int idx);
204204

205205
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_typename")]
206-
public static extern nint _lua_typename(lua_State L, int tp);
206+
private static extern nint _lua_typename(lua_State L, int tp);
207207
public static string? lua_typename(lua_State L, int tp)
208208
{
209209
return Marshal.PtrToStringAnsi(_lua_typename(L, tp));
@@ -228,7 +228,7 @@ public static lua_State lua_newstate(lua_Alloc? f, nuint ud)
228228
public static extern int lua_toboolean(lua_State L, int idx);
229229

230230
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_tolstring")]
231-
public static extern nint _lua_tolstring(lua_State L, int idx, ref size_t len);
231+
private static extern nint _lua_tolstring(lua_State L, int idx, ref size_t len);
232232
public static string? lua_tolstring(lua_State L, int idx, ref size_t len)
233233
{
234234
return Marshal.PtrToStringAnsi(_lua_tolstring(L, idx, ref len));
@@ -238,7 +238,7 @@ public static lua_State lua_newstate(lua_Alloc? f, nuint ud)
238238
public static extern size_t lua_objlen(lua_State L, int idx);
239239

240240
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_tocfunction")]
241-
public static extern nint _lua_tocfunction(lua_State L, int idx);
241+
private static extern nint _lua_tocfunction(lua_State L, int idx);
242242
public static lua_CFunction? lua_tocfunction(lua_State L, int idx)
243243
{
244244
nint ret = _lua_tocfunction(L, idx);
@@ -275,14 +275,14 @@ public static lua_State lua_newstate(lua_Alloc? f, nuint ud)
275275

276276
// TODO:
277277
// [DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_pushfstring")]
278-
// public static extern nint _lua_pushfstring(lua_State L, string fmt, params string[] args);
278+
// private static extern nint _lua_pushfstring(lua_State L, string fmt, params string[] args);
279279
// public static string? lua_pushfstring(lua_State L, string fmt, params string[] args)
280280
// {
281281
// return Marshal.PtrToStringAnsi(_lua_pushfstring(L, fmt, args));
282282
// }
283283

284284
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_pushcclosure")]
285-
public static extern void _lua_pushcclosure(lua_State L, nint fn, int n);
285+
private static extern void _lua_pushcclosure(lua_State L, nint fn, int n);
286286
public static void lua_pushcclosure(lua_State L, lua_CFunction? fn, int n)
287287
{
288288
_lua_pushcclosure(L, fn == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate(fn), n);
@@ -346,21 +346,21 @@ public static void lua_pushcclosure(lua_State L, lua_CFunction? fn, int n)
346346
public static extern int lua_pcall(lua_State L, int nargs, int nresults, int errfunc);
347347

348348
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_cpcall")]
349-
public static extern int _lua_cpcall(lua_State L, nint func, nuint ud);
349+
private static extern int _lua_cpcall(lua_State L, nint func, nuint ud);
350350
public static int lua_cpcall(lua_State L, lua_CFunction? func, nuint ud)
351351
{
352352
return _lua_cpcall(L, func == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate<lua_CFunction>(func), ud);
353353
}
354354

355355
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_load")]
356-
public static extern int _lua_load(lua_State L, nint reader, nuint dt, string chunkname);
356+
private static extern int _lua_load(lua_State L, nint reader, nuint dt, string chunkname);
357357
public static int lua_load(lua_State L, lua_Reader? reader, nuint dt, string chunkname)
358358
{
359359
return _lua_load(L, reader == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate<lua_Reader>(reader), dt, chunkname);
360360
}
361361

362362
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_dump")]
363-
public static extern int _lua_dump(lua_State L, nint writer, nuint data);
363+
private static extern int _lua_dump(lua_State L, nint writer, nuint data);
364364
public static int lua_dump(lua_State L, lua_Writer? writer, nuint data)
365365
{
366366
return _lua_dump(L, writer == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate<lua_Writer>(writer), data);
@@ -400,7 +400,7 @@ public static int lua_dump(lua_State L, lua_Writer? writer, nuint data)
400400
public static extern lua_Alloc lua_getallocf(lua_State L, out nuint ud);
401401

402402
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_setallocf")]
403-
public static extern void _lua_setallocf(lua_State L, nint f, nuint ud);
403+
private static extern void _lua_setallocf(lua_State L, nint f, nuint ud);
404404
public static void lua_setallocf(lua_State L, lua_Alloc? f, nuint ud)
405405
{
406406
_lua_setallocf(L, f == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate<lua_Alloc>(f), ud);
@@ -529,42 +529,42 @@ public static int lua_getgccount(lua_State L)
529529
public static extern int lua_getinfo(lua_State L, string what, lua_Debug ar);
530530

531531
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_getlocal")]
532-
public static extern nint _lua_getlocal(lua_State L, lua_Debug ar, int n);
532+
private static extern nint _lua_getlocal(lua_State L, lua_Debug ar, int n);
533533
public static string? lua_getlocal(lua_State L, lua_Debug ar, int n)
534534
{
535535
return Marshal.PtrToStringAnsi(_lua_getlocal(L, ar, n));
536536
}
537537

538538
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_setlocal")]
539-
public static extern nint _lua_setlocal(lua_State L, lua_Debug ar, int n);
539+
private static extern nint _lua_setlocal(lua_State L, lua_Debug ar, int n);
540540
public static string? lua_setlocal(lua_State L, lua_Debug ar, int n)
541541
{
542542
return Marshal.PtrToStringAnsi(_lua_setlocal(L, ar, n));
543543
}
544544

545545
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_getupvalue")]
546-
public static extern nint _lua_getupvalue(lua_State L, int funcindex, int n);
546+
private static extern nint _lua_getupvalue(lua_State L, int funcindex, int n);
547547
public static string? lua_getupvalue(lua_State L, int funcindex, int n)
548548
{
549549
return Marshal.PtrToStringAnsi(_lua_getupvalue(L, funcindex, n));
550550
}
551551

552552
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_setupvalue")]
553-
public static extern nint _lua_setupvalue(lua_State L, int funcindex, int n);
553+
private static extern nint _lua_setupvalue(lua_State L, int funcindex, int n);
554554
public static string? lua_setupvalue(lua_State L, int funcindex, int n)
555555
{
556556
return Marshal.PtrToStringAnsi(_lua_setupvalue(L, funcindex, n));
557557
}
558558

559559
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_sethook")]
560-
public static extern int _lua_sethook(lua_State L, nint func, int mask, int count);
560+
private static extern int _lua_sethook(lua_State L, nint func, int mask, int count);
561561
public static int lua_sethook(lua_State L, lua_Hook? func, int mask, int count)
562562
{
563563
return _lua_sethook(L, func == null ? ((nint) 0) : Marshal.GetFunctionPointerForDelegate<lua_Hook>(func), mask, count);
564564
}
565565

566566
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "lua_gethook")]
567-
public static extern nint _lua_gethook(lua_State L);
567+
private static extern nint _lua_gethook(lua_State L);
568568
public static lua_Hook? lua_gethook(lua_State L)
569569
{
570570
nint ret = _lua_gethook(L);
@@ -608,14 +608,14 @@ public static void luaL_setn(lua_State L, int i, int j)
608608
public static extern int luaL_argerror(lua_State L, int numarg, string extramsg);
609609

610610
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "luaL_checklstring")]
611-
public static extern nint _luaL_checklstring(lua_State L, int numArg, ref size_t l);
611+
private static extern nint _luaL_checklstring(lua_State L, int numArg, ref size_t l);
612612
public static string? luaL_checklstring(lua_State L, int numArg, ref size_t l)
613613
{
614614
return Marshal.PtrToStringAnsi(_luaL_checklstring(L, numArg, ref l));
615615
}
616616

617617
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "luaL_optlstring")]
618-
public static extern nint _luaL_optlstring(lua_State L, int numArg, string def, ref size_t l);
618+
private static extern nint _luaL_optlstring(lua_State L, int numArg, string def, ref size_t l);
619619
public static string? luaL_optlstring(lua_State L, int numArg, string def, ref size_t l)
620620
{
621621
return Marshal.PtrToStringAnsi(_luaL_optlstring(L, numArg, def, ref l));
@@ -677,14 +677,14 @@ public static void luaL_setn(lua_State L, int i, int j)
677677
public static extern lua_State luaL_newstate();
678678

679679
[DllImport(DllName, CallingConvention = Convention, EntryPoint = "luaL_gsub")]
680-
public static extern nint _luaL_gsub(lua_State L, string s, string p, string r);
680+
private static extern nint _luaL_gsub(lua_State L, string s, string p, string r);
681681
public static string? luaL_gsub(lua_State L, string s, string p, string r)
682682
{
683683
return Marshal.PtrToStringAnsi(_luaL_gsub(L, s, p, r));
684684
}
685685

686686
[DllImport(DllName, CallingConvention= Convention, EntryPoint = "luaL_findtable")]
687-
public static extern nint _luaL_findtable(lua_State L, int idx, string fname, int szhint);
687+
private static extern nint _luaL_findtable(lua_State L, int idx, string fname, int szhint);
688688
public static string? luaL_findtable(lua_State L, int idx, string fname, int szhint)
689689
{
690690
return Marshal.PtrToStringAnsi(_luaL_findtable(L, idx, fname, szhint));

0 commit comments

Comments
 (0)