@@ -40,12 +40,17 @@ If you are just here to use the library, you can get by without having to worry
40
40
41
41
Example Usage Lua5.4.4:
42
42
``` C#
43
+ // test1.csproj
44
+ // <PropertyGroup>
45
+ // ...
46
+ // <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
47
+ // </PropertyGroup>
43
48
using Lua54 ;
44
49
using static Lua54 .Lua ;
45
50
46
- namespace LuaNET ;
51
+ namespace TestLua ;
47
52
48
- class Project
53
+ public class Test1
49
54
{
50
55
51
56
public static int lfunc (lua_State L )
@@ -59,7 +64,7 @@ class Project
59
64
public static void Main (String [] args )
60
65
{
61
66
lua_State L = luaL_newstate ();
62
- if (L .Handle == UIntPtr . Zero )
67
+ if (L .Handle == 0 )
63
68
{
64
69
Console .WriteLine (" Unable to create context!" );
65
70
}
@@ -76,12 +81,17 @@ class Project
76
81
77
82
Example Usage LuaJIT:
78
83
``` C#
84
+ // test2.csproj
85
+ // <PropertyGroup>
86
+ // ...
87
+ // <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
88
+ // </PropertyGroup>
79
89
using LuaJIT ;
80
90
using static LuaJIT .Lua ;
81
91
82
- namespace LuaNET ;
92
+ namespace TestLua ;
83
93
84
- class Project
94
+ public class Test2
85
95
{
86
96
87
97
public static int lfunc (lua_State L )
@@ -95,7 +105,7 @@ class Project
95
105
public static void Main (String [] args )
96
106
{
97
107
lua_State L = luaL_newstate ();
98
- if (L .Handle == UIntPtr . Zero )
108
+ if (L .Handle == 0 )
99
109
{
100
110
Console .WriteLine (" Unable to create context!" );
101
111
}
@@ -112,7 +122,7 @@ class Project
112
122
113
123
Example Usage NativeAOT DLL Library:
114
124
``` C#
115
- // test2 .csproj
125
+ // test3 .csproj
116
126
// <PropertyGroup>
117
127
// ...
118
128
// <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@@ -123,9 +133,9 @@ using System.Runtime.InteropServices;
123
133
using LuaJIT ;
124
134
using static LuaJIT .Lua ;
125
135
126
- namespace test2 ;
136
+ namespace TestLua ;
127
137
128
- public unsafe class Test2
138
+ public unsafe class Test3
129
139
{
130
140
131
141
[UnmanagedCallersOnly ]
@@ -151,26 +161,27 @@ public unsafe class Test2
151
161
152
162
}
153
163
154
- // test1.csproj
155
-
164
+ // test4.csproj
165
+ // <PropertyGroup>
166
+ // ...
167
+ // <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
168
+ // </PropertyGroup>
156
169
using LuaJIT ;
157
170
using static LuaJIT .Lua ;
158
171
159
- namespace test1 ;
172
+ namespace test4 ;
160
173
161
174
public class Test1
162
175
{
163
176
164
177
public static void Main (string [] args )
165
178
{
166
179
lua_State L = luaL_newstate ();
167
- if (L .Handle == UIntPtr . Zero )
180
+ if (L .Handle == 0 )
168
181
{
169
182
Console .WriteLine (" Unable to create context!" );
170
183
}
171
184
luaL_openlibs (L );
172
-
173
- // require("test2.dll");
174
185
lua_getglobal (L , " require" );
175
186
lua_pushstring (L , " test2" );
176
187
int result = lua_pcall (L , 1 , 0 , 0 );
@@ -179,11 +190,9 @@ public class Test1
179
190
string ? err = luaL_checkstring (L , 1 );
180
191
if (err != null )
181
192
{
182
- Console .WriteLine ($" 1 Error Result: {err }" );
193
+ Console .WriteLine ($" 1 Result: {err }" );
183
194
}
184
195
}
185
-
186
- // print(_G.test2.GetHello())
187
196
lua_getglobal (L , " test2" );
188
197
lua_getglobal (L , " print" );
189
198
lua_getfield (L , 1 , " GetHello" );
@@ -193,7 +202,7 @@ public class Test1
193
202
string ? err = luaL_checkstring (L , 1 );
194
203
if (err != null )
195
204
{
196
- Console .WriteLine ($" 2 Error Result: {err }" );
205
+ Console .WriteLine ($" 2 Result: {err }" );
197
206
}
198
207
}
199
208
result = lua_pcall (L , 1 , 0 , 0 );
@@ -202,10 +211,9 @@ public class Test1
202
211
string ? err = luaL_checkstring (L , 1 );
203
212
if (err != null )
204
213
{
205
- Console .WriteLine ($" 3 Error Result: {err }" );
214
+ Console .WriteLine ($" 3 Result: {err }" );
206
215
}
207
216
}
208
- // pop test2
209
217
lua_pop (L , 1 );
210
218
211
219
lua_close (L );
0 commit comments