Kernell Posted August 20, 2014 Posted August 20, 2014 I'm trying to define custom methods and properties of existing classes. I do not like to use the variable names with a lowercase letter (I like CamelCase style). In this article (https://wiki.multitheftauto.com/wiki/OOP) described what properties MTA creates for metatables. I tried to define their own properties, but this do not work: local ElementMT = debug.getmetatable( Element ); Element.__get = -- It's funny that __get table does not exist. { Health = getElementHealth; }; debug.setmetatable( Element, ElementMT ); local pElement = Element( "test" ); pElement.health = 13; -- for testing outputDebugString( tostring( pElement.Health ) ); -- nil (do not work) How to make custom properties and methods? Не оказываю поддержку посредством личных сообщений, ICQ, ВК и тому подобное. Все вопросы задавайте на форуме.
ixjf Posted August 20, 2014 Posted August 20, 2014 Take a look at sbx320's classlib. I used to know how to code, but then I took an arrow in the knee. Project Redivivus - Remaking Old School MTA With New Code MTA 0.6 Nightly 1 released
Kernell Posted August 20, 2014 Author Posted August 20, 2014 No, thanks. I have my own library, with the ability to define custom properties like as C#. I'm interested in the native way of the MTA, without workarounds. Не оказываю поддержку посредством личных сообщений, ICQ, ВК и тому подобное. Все вопросы задавайте на форуме.
ixjf Posted August 20, 2014 Posted August 20, 2014 I'm not telling you to use that library, I mentioned it so you can see how to do it the native way. That's just the way it has to go due to the MTA OOP design. I used to know how to code, but then I took an arrow in the knee. Project Redivivus - Remaking Old School MTA With New Code MTA 0.6 Nightly 1 released
Kernell Posted August 20, 2014 Author Posted August 20, 2014 I do not see that you use the native OOP from the MTA. I did not even see that you use the override methods and properties as required in the first message. Не оказываю поддержку посредством личных сообщений, ICQ, ВК и тому подобное. Все вопросы задавайте на форуме.
Jusonex Posted August 20, 2014 Posted August 20, 2014 Class information are stored in the Lua registry internally. There are two ways to access __get/__set: 1.) Use the userdata (element) instead of the class: debug.getmetatable(element) 2.) Use the registry local classInfo = debug.getregistry().mt local getFunctions = classInfo.Account.__get
Kernell Posted August 20, 2014 Author Posted August 20, 2014 Did not know about Lua registry. Thank you very much, it really helped me! Issue has been resolved Не оказываю поддержку посредством личных сообщений, ICQ, ВК и тому подобное. Все вопросы задавайте на форуме.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now