Jump to content
  • Advertisement
Sign in to follow this  
Luxx

LuaInterface - Nested Tables, Anonymous Functions

This topic is 3145 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!