You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the above patch you'll have additional functionality:
localplayer=getPlayer();
addText("Hello, " ..player:getName() .."!\r\n");
addText("Your ID is " ..player:getId() .."\r\n");
addText("The player object __tostring method returns: " ..player:__tostring());
sendOk();
resulting in:
Basically, getPlayer() returns a metatable + reference to the current player. Using getName() on this object in Lua, you can use the previously saved player reference (in the lua stack) to get the username.
The __tostring method is used for functions that support __tostring (for example, print()).
The text was updated successfully, but these errors were encountered:
diamondo25
changed the title
[POC] Using lua metatables for more OOP scripting
[POC] Using lua metatables for more object-oriented scripts
Oct 18, 2016
Uh oh!
There was an error while loading. Please reload this page.
I've made a proof of concept to unbloat our Lua global scope, so you can do more object-oriented programming in Lua.
https://gist.github.com/diamondo25/02cf385903f955ffd0a07d611cfb7551
With the above patch you'll have additional functionality:
resulting in:
Basically,
getPlayer()
returns a metatable + reference to the current player. UsinggetName()
on this object in Lua, you can use the previously saved player reference (in the lua stack) to get the username.The
__tostring
method is used for functions that support__tostring
(for example,print()
).The text was updated successfully, but these errors were encountered: