lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi!

I've been tinkering a bit with Lua and C#. I'm trying to use the __index metatable event to re-route function calls to the C# side. My setup is like this:

On the Lua-Side I have a 'handle' to a C# object. This handle is in a table, which has a metatable attached to it. I use the metatable to intercept the index event. Here is some code, which evolved somewhat out of the ClassesWithMetatables article in the Wiki. It currently ignores a lot of stuff, but I want to get this simple thing working first before making everything 'nice':

function myIndex(t, func)
  return luaNET.call(t.handle, func);
end;

LuaNETObject = {};
LuaNETObject_mt = { __index = myIndex };

function LuaNETObject:new(handle)
  return setmetatable( {handle = handle}, LuaNETObject_mt);
end;

-- 1 is a valid handle
testObj = LuaNETObject:new(1);

-- should reroute the call
testObj:Hello();

OK, now the above code does call the C# function of the object in testObj correctly (it just prints something out), but after the last line Lua complains with this:

[string "function myIndex(t, func) return luaNET...."]:1: attempt to call method `Hello' (a nil value)

Obviously, the table testObj did not contain a Hello-function. But, I thought if the index event handles this, then Lua would be silent. Can somebody help me out? Is there a clean way of achieving this? I hope my explanation is not too obscure. So, basically I would like to somehow signal Lua in the myIndex function that 'everything went alright'.

BTW, this is not related to Lua.NET ... I just couldn't find a better name for this, other than luaNET.

Thanks,
Marco