LuaInterface - Nested Tables, Anonymous Functions

Started by
3 comments, last by Luxx 14 years, 5 months ago
There exists a table Mobiles = { testFunc = function () ... end, [1] = { OnLoad = function() ... end, }, [2] = { OnLoad = function() ... end, }, ... } Mobiles is nested in another table, but it is irrelevant to my issue. I'm able to call Mobiles[1]:OnLoad(), without any issues. However, I need to be able to execute anonymous functions in a tested table via C# using LuaInterface. I'm able properly make other calls using GetFunction, such as lua.GetFunction( "Mobiles.testFunc" ).Call( ... ). Those work fine. It's when I attempt to access an entry from the table, and try to call OnLoad, that it does not work. It's likely because I don't understand how fullName argument works for GetFunction, with anonymous functions and tables in the mix. Would I do... lua.GetFunction( "Mobiles[1].OnLoad" ).Call( ... ) or lua.GetFunction( "Mobiles[1]:OnLoad" ).Call( ... ) or lua.GetFunction( "Mobiles.1.OnLoad" ).Call( ... ) I don't know how describe the fullName of an anonymous function in a indexed entry of a nested table.
Advertisement
Problem solved. :
Table had to be initialized using ["1"], not [1] for GetFunction("Mobiles.1.OnLoad").Call( ... ) to work.
Nice,

I haven't gotten that far in my own work yet, but good to know other people are using LuaInterface.

------------------------------

redwoodpixel.com

Now I'm no expect, and have very briefly actually used Lua, but, instead of doing this:

GetFunction("Mobiles.1.OnLoad").Call( ... )

Would it not be possible to make the table entry as [1] and then just call it like this?:

GetFunction("Mobiles[1].OnLoad").Call( ... )
I've tried that; it was the first type of format I mentioned. GetFunction doesn't seem to like index access that way, especially when the keys are the normal mapping indices (1, 2, 3, etc..). It only works with the syntactic sugar format and requires that keys be custom.

So, table requires a ["1"] vs [1], where the key are "1" vs 1. The former is accessed as I mentioned in my second post, I have no idea on how to access a normal mapped index value. :\

This topic is closed to new replies.

Advertisement