Skip to content

Commit 2876aa7

Browse files
Fix hxcpp compilation error.
1 parent 3864e74 commit 2876aa7

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

src/Lua.hx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ private abstract Callable<T:Function>(T) to T {
3030
private typedef IntBool = Bool;
3131
#elseif cpp
3232
@:include("lua.hpp")
33-
@:native("lua_State *")
34-
extern class State {}
33+
@:native("lua_State")
34+
extern class NativeState {}
35+
36+
typedef State = cpp.Pointer<NativeState>;
3537

3638
private abstract CString(cpp.ConstCharStar) from cpp.ConstCharStar to cpp.ConstCharStar {
3739
@:from static inline function fromString(s:String):CString {

test/Main.hx

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
import Lua;
2+
23
class Main {
3-
static function main() {
4-
Sys.println("Hello World!");
5-
var vm:State = Lua.newstate();
6-
Sys.println("VM Created");
7-
Lua.openlibs(vm);
8-
Sys.println("libs opened");
9-
Lua.dofile(vm, "script.lua");
10-
Sys.println("file loaded");
11-
Lua.getglobal(vm, "foo");
12-
Lua.pushinteger(vm, 1);
13-
Lua.pushnumber(vm, 2.0);
14-
Lua.pushstring(vm, "three");
15-
Lua.pcall(vm, 3, 0, 1);
16-
trace("closing vm");
17-
Lua.close(vm);
18-
Sys.println("vm closed");
4+
var state:State;
5+
6+
function new() {
7+
state = Lua.newstate();
8+
Reflect.setField(this, "state", Lua.newstate());
9+
}
10+
11+
static function main() {
12+
Sys.println("Hello World!");
13+
var vm:State = Lua.newstate();
14+
Sys.println("VM Created");
15+
Lua.openlibs(vm);
16+
Sys.println("libs opened");
17+
Lua.dofile(vm, "script.lua");
18+
Sys.println("file loaded");
19+
Lua.getglobal(vm, "foo");
20+
Lua.pushinteger(vm, 1);
21+
Lua.pushnumber(vm, 2.0);
22+
Lua.pushstring(vm, "three");
23+
Lua.pcall(vm, 3, 0, 1);
24+
trace("closing vm");
25+
Lua.close(vm);
26+
Sys.println("vm closed");
27+
28+
new Main();
29+
}
1930
}
20-
}

0 commit comments

Comments
 (0)