Trying to write a function in C# (to redirect print's output to stdio to a GUI window). Works fine on Linux, but crashing on a Windows7 64-bit computer. (This is my first interaction with LuaSharp and Lua in general, so I might be doing something stupid). I am using the Lua Windows binaries for x86 (the ones made for 64-bit explicitly did not load from LuaSharp.dll).
Test code:
// CSharp code to assign Lua's print function
public static class LuaEnv {
public static void Main() {
LuaSharp.Lua state = new LuaSharp.Lua();
setEnvironment(state);
LuaSharp.LuaFunction p = (LuaSharp.LuaFunction)state["print"];
p.Call(1);
p.Call(2);
p.Call(3);
}
public static void setEnvironment(LuaSharp.Lua state) {
state["print"] = new MyPrint();
}
public class MyPrint : LuaSharp.ClrFunction {
public MyPrint() {
}
protected override object[] OnInvoke(LuaSharp.Lua state, object[] args) {
System.Console.Write("MyPrint: ");
System.Console.WriteLine(args[0]);
return new object[] {null};
}
}
}
Compiled on Linux under Mono 2.6.7 with:
gmcs -target:exe \
LuaTest.cs \
-r:LuaSharp \
-out:LuaTest.exe
C:\Users\dblank\Desktop\Calico\languages\Lua>mono LuaTest.exe
MyPrint: 1
Stacktrace:
at (wrapper managed-to-native) LuaWrap.LuaLib.lua_call (intptr,int,int) <0x00004>
at (wrapper managed-to-native) LuaWrap.LuaLib.lua_call (intptr,int,int) <0x00004>
at LuaSharp.LuaFunction.Call (object[]) <0x000fa>
at LuaEnv.Main () <0x000ea>
at (wrapper runtime-invoke) object.runtime_invoke_void (object,intptr,intptr,intptr) <0x0003a>
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
C:\Users\dblank\Desktop\Calico\languages\Lua>
I've also tried running with later versions of Mono, and it seems to crash after it does the print.
Any ideas appreciated!
-Doug