[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Using index-event to call external function
- From: Marco Kögler <marco.koegler@...>
- Date: Wed, 23 Apr 2003 08:11:25 +0200
Nick Trout wrote:
The following might work better. You can't quite just put
"testObj.Hello" because Lua will think its an assignment. I put a dummy
Hello function in your luaNET object. As Riki pointed out, __index needs
to return the function object. It's the "luaNET.call(...)" in myIndex
which involkes the function object. You try to involke the function
object twice, and on the second call it's a nil.
Yeah, thanks to Riki I already hit myself :)
I understand now. While your way works, it requires the called function
to be a part of luaNET, which I don't want. The proxy should work with
any class. The script should not have specific knowledge of this. Right
now, I'm thinking along the line of setting up the function to be called
on the C# side in myIndex and returning an executing call function:
function myIndex(t, func)
luaNET.select(t.handle, func)
return luaNET.call
end;
The luaNET.select prepares the function to be called on the C# side
(using reflection it finds the Method to call, etc...). The luaNET.call
handles the marshalling of parameters and return values.
Another name might be CSharpProxy as luaNET is general and implies its
embedded in .NET??
The method I use is not limited to C# (any .NET language should work)
... but NETProxy seems to be a way to go :)
Thanks for everybodies help,
Marco
-----
luaNET = {
Hello = function(handle) return "Hello! "..handle end,
call = function(handle,fn) return luaNET[fn](handle) end
}
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
print( testObj.Hello )