0

I've got the following scenario:

  1. I registered a c# function in nlua
  2. This function is called like this in the lua script: SomeFunction({Amount = 1})
  3. The c# function gets called but now the Amount is some arbitrary huge double

The code in which I register the function:

Lua LuaInterface = new Lua();
someFunction = (LuaTable t) => DoSomething(t);
LuaInterface.RegisterFunction("SomeFunction", someFunction.Target, someFunction.Method);

If I use the debugger, t is for example {{ Amount = -2,05689484611373E-178 }}

I've spent about two hours finding a bug in my code (the real one is far more complex) and this is just what I reduced the problem to.

l.k.1234
  • 78
  • 6
  • Can you show how `DoSomething` is accessing `t.Amount` from C#? – greatwolf Jan 05 '15 at 23:52
  • By t["Amount"]. This returns a object. When I parse this object to a int I get a OverflowException – l.k.1234 Jan 06 '15 at 09:24
  • You don't need to use RegisterFunction to use delegates you can simply set a global variable using LuaInterface ["SomeFunction"] = someFunction; And call from Lua using "SomeFunction(t)". https://github.com/NLua/NLua/blob/master/tests/LuaTests.cs#L2374 – Vinicius Jarina Jan 06 '15 at 18:02
  • @ Vinicius Jarina As far as I'm concerned SomeFunction({Amount = 1}) is valid Lua syntax. All scripts I have are written this way so it would be a huge effort to change all of them. Your way of registering the functions got rid of the exception but only by never calling the delegate. I guess I did something wrong there. `LuaInterface["SomeFunction"] = new Action((LuaTable t) => DoSomething(t));` – l.k.1234 Jan 07 '15 at 18:41
  • Hi @I.k 1234 I am not sure what is wrong with your code. But this is working fine here http://screencast.com/t/qxmR2p9MBx https://gist.github.com/viniciusjarina/18106975e78ac811a73b – Vinicius Jarina Jan 09 '15 at 19:16
  • @Vinicius Jarina Yeah it's kinda strange. I'll try to reproduce the bug on a different computer. Maybe its just some really uncommon external factor. – l.k.1234 Jan 10 '15 at 13:08
  • @I.k 1234 Try to update your Mono or you Xamarin.iOS/Xamarin.Android to the latest version. – Vinicius Jarina Jan 10 '15 at 20:39

0 Answers0