Sign in to follow this  
Luxx

LuaInterface - Nested Tables, Anonymous Functions

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Problem solved. :
Table had to be initialized using ["1"], not [1] for GetFunction("Mobiles.1.OnLoad").Call( ... ) to work.

Share this post


Link to post
Share on other sites
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( ... )

Share this post


Link to post
Share on other sites
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. :\

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this