8000 [POC] Using lua metatables for more object-oriented scripts · Issue #13 · retep998/Vana · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[POC] Using lua metatables for more object-oriented scripts #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
diamondo25 opened this issue Oct 17, 2016 · 0 comments
Open

[POC] Using lua metatables for more object-oriented scripts #13

diamondo25 opened this issue Oct 17, 2016 · 0 comments

Comments

@diamondo25
Copy link
Contributor
diamondo25 commented Oct 17, 2016

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:

local player = 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()).

@diamondo25 diamondo25 changed the title [POC] Using lua metatables for more OOP scripting [POC] Using lua metatables for more object-oriented scripts Oct 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0