I found a very good reference for tables and thought I'd share it.
http://www.gammon.com.au/forum/?id=6036
table.foreach is a very useful function.
Professional Software Development Tools
I found a very good reference for tables and thought I'd share it.
http://www.gammon.com.au/forum/?id=6036
table.foreach is a very useful function.
Action Plugins
AllOn | Box | Class | Code | Cursor | DXML | Error | Frames | GlobalPaths | Group | INIPlus |KeyBind | KeyLock | MathEx | Menu | Name | Project | Resize | StatusBar
Download
to the the power of LUA Tables
Thnx
Nice Thread
I should write a metatable tutorial one day, not just for OOP coding in Lua,
but for customizing the indexes/operators/pairs functions etc.
There's so much you can do with Lua tables, there is no real limit actually.
So I'll be the n00b and ask...what's a metatable?
Action Plugins
AllOn | Box | Class | Code | Cursor | DXML | Error | Frames | GlobalPaths | Group | INIPlus |KeyBind | KeyLock | MathEx | Menu | Name | Project | Resize | StatusBar
Download
The metatable contains information about an object, for example, a luatable. You can set functions
and data here that belongs to just the object and can't be accessed without calling set/getmetatable.
You can set the type, the getter/setter functions (for tables) and even change how operators react
on certain objects.
For example, you can write code in Lua that causes 'szString * 3' to repeat that string 3 times.
Or e.g.
This is a bit complicated stuff, but as Sakuya said, there's so much you can do with it.Code:local newString = ("LoL")*100;
This is the reason why, in my Object plugin, you can't loop through the Object table,
you can't change anything in it and why you can use hObjectHandle.Properties.Text = "Test"; etc.
All that is triggered in the metatable![]()
Hey Bas,
Looking forward to the tutorial... Sounds like metatables could be a chapter in one of Stephen Hawkings books on quantum astrophysics![]()
I think astrophysics are a bit more complicated than this haha![]()
A metatable is just another table attached to a table containing information
about the table it's attached to![]()
Action Plugins
AllOn | Box | Class | Code | Cursor | DXML | Error | Frames | GlobalPaths | Group | INIPlus |KeyBind | KeyLock | MathEx | Menu | Name | Project | Resize | StatusBar
Download
Hi all,
Check this link out:
http://blog.tplus1.com/index.php/200...able-examples/
Nice link, but that's the very basic information regarding indexes in metatables. I will
see if I can put up a tutorial based on the system Object is using, including filtering
allowed keys and values.
small remark from the LUA 5.1 ref manual:
www.lua.org/manual/5.1/manual.html#7Functions table.foreach and table.foreachi are deprecated.
You can use a for loop with pairs or ipairs instead.
John,
That's true, however those functions can be customized and you
can make custom pairs functions. But then again, this can also be
done in the metatables![]()