Skip to content

Commit c86548c

Browse files
Fix hxcpp reader/writer callbacks
1 parent 2876aa7 commit c86548c

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/Lua.hx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ private abstract IntBool(Int) from Int to Int {
6868
}
6969

7070
private class Misc {
71-
public static function writer(L:State, p:cpp.ConstStar<cpp.Void>, sz:cpp.SizeT, ud:cpp.Star<cpp.Void>):Int {
71+
public static function writer(L:cpp.RawPointer<NativeState>, p:cpp.RawConstPointer<cpp.Void>, sz:cpp.SizeT, ud:cpp.Star<cpp.Void>):Int {
7272
var func:(State, haxe.io.Bytes) -> Int = cast ud;
73-
return func(L,haxe.io.Bytes.ofData(cpp.Pointer.fromStar(cast p).toUnmanagedArray(sz)));
73+
return func(cpp.Pointer.fromRaw(L),haxe.io.Bytes.ofData(cpp.Pointer.fromRaw((cast p:cpp.RawPointer<cpp.UInt8>)).toUnmanagedArray(sz)));
7474
}
7575

76-
public static function reader(L:State,ud:cpp.Star<cpp.Void>,sz:cpp.Star<cpp.SizeT>):cpp.ConstCharStar {
76+
public static function reader(L:cpp.RawPointer<NativeState>,ud:cpp.Star<cpp.Void>,sz:cpp.RawPointer<cpp.SizeT>):cpp.ConstCharStar {
7777
var func:(State)->haxe.io.Bytes = cast ud;
78-
var b = func(L);
79-
untyped __cpp__("*sz = {0}",b.length);
78+
var b = func(cpp.Pointer.fromRaw(L));
79+
sz[0] = b.length;
8080
return cast cpp.Pointer.ofArray(b.getData()).constRaw;
8181

8282
}
@@ -273,7 +273,7 @@ extern class Lua {
273273
static function cpcall<T:Dynamic>(L:State, func:LuaCFunction, ud:T):Int;
274274
#if cpp
275275
@:native("lua_load")
276-
private static function _load(L:State, reader:cpp.Callable<(State,cpp.Star<cpp.Void>,cpp.Star<cpp.SizeT>)->cpp.ConstCharStar>, dt:cpp.Star<cpp.Void>, chunkname:CString):Int;
276+
private static function _load(L:State, reader:cpp.Callable<(cpp.RawPointer<NativeState>,cpp.Star<cpp.Void>,cpp.RawPointer<cpp.SizeT>)->cpp.ConstCharStar>, dt:cpp.Star<cpp.Void>, chunkname:CString):Int;
277277
static inline function load(L:State,reader:(State)->haxe.io.Bytes,chunkname:String):Int {
278278
return _load(L,cpp.Callable.fromStaticFunction(Misc.reader),cast reader,chunkname);
279279
}
@@ -283,9 +283,10 @@ extern class Lua {
283283
#end
284284
#if cpp
285285
@:native("lua_dump")
286-
private static function _dump(L:State,writer:cpp.Callable<(State,cpp.ConstStar<cpp.Void>,cpp.SizeT,cpp.Star<cpp.Void>)->Int>,ud:cpp.Star<cpp.Void>):Int;
286+
private static function _dump(L:State,
287+
writer:cpp.Callable<(cpp.RawPointer<NativeState>,cpp.RawConstPointer<cpp.Void>,cpp.SizeT,cpp.Star<cpp.Void>)->Int>,ud:cpp.Star<cpp.Void>):Int;
287288
static inline function dump(L:State,writer:(State,haxe.io.Bytes)->Int):Int {
288-
return _dump(L,cpp.Callable.fromStaticFunction(Misc.writer),cast writer);
289+
return _dump(L,cpp.Function.fromStaticFunction(Misc.writer),cast writer);
289290
}
290291
#elseif hl
291292
@:skipHL

test/Main.hx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Main {
2222
Lua.pushstring(vm, "three");
2323
Lua.pcall(vm, 3, 0, 1);
2424
trace("closing vm");
25+
Lua.dump(vm, (s, b) -> b.length);
2526
Lua.close(vm);
2627
Sys.println("vm closed");
2728

0 commit comments

Comments
 (0)