sbx320 / lua_utils Goto Github PK
View Code? Open in Web Editor NEWA collection of utility Lua scripts usable in conjunction with MTA San Andreas, improving the use of asynchronous and object-oriented scripting
License: MIT License
A collection of utility Lua scripts usable in conjunction with MTA San Andreas, improving the use of asynchronous and object-oriented scripting
License: MIT License
Hey,
I love classlib, thanks for distributing it open source.
I have a question though, I am probably using destroy( )
wrong and I'm trying to look for the right way to do it but cannot find good examples and I am not sure if this is an error of my own or if it's the utility's fault.
ERROR: classlib.lua:126: bad argument #1 to 'pairs' (table expected, got nil)
That points to parentClasses
and according to my knowledge my class/object has no parent classes, or at least I don't define them anywhere.
Here is the script I am trying to create.
local Class = { }
function Class:connect( hostname, username, password, database )
self.instance = enew( Connection.create( 'mysql', 'dbname=' .. database .. ';host=' .. hostname, username, password, 'share=0;batch=0;log=1;tag=script' ), self )
if ( self.instance ) then
return self.instance
end
return false
end
function Class:disconnect( )
if ( isElement( self.instance ) ) then
self.instance:destroy( )
end
-- delete( self )
end
local database = new( Class )
database:connect( 'hostname', 'username', 'password', 'database' )
database:disconnect( )
What possibly could be wrong? The delete( self )
has been commented out, but what I want Class:disconnect( )
to do, is destroy the Connection
element and essentially just delete the object.
Feel free to let me know if I should be doing my class in any different way. I am really new to the MTA OOP/Lua OOP scene so I'm trying to get into that to get better :-)
Whenever I try to create a new class object with enew
of a player element, it throws a warning to the debug log, saying that onElementDestroy event is already being handled by the function, how is this possible? MTA restricts listening to certain player events?
enew( getPlayerFromName( 'Socialz' ), classes.player )
WARNING: classlib.lua:59: Bad usage @ 'addEventHandler' ['onElementDestroy' with this function is already handled]
I added getElementType(element) ~= 'player'
to my version, but if I understand it right, we should never ignore this event as it deletes stuff from memory and if it's never deleted we have a memory leak.
Using onPlayerQuit instead of onElementDestroy did not resolve the warning.
All functions that use getmetatable
use the previously set metatable instead of the one stored in the Lua registry.
i copy enew example from wiki ,but it can not work and ouput attempt to call method 'boom' (a nil value)
Class1
|
Class2 (inherits from 1)
|
Class3 (inherits from 2)
|
Class4 (inherits from 3)
currently: new Class4 => call Class 3 virtual => call Class 2 virtual => call Class 1 virtual => call Class 4 constructor
expected: new Class4 => call Class 1 virtual => call Class 2 virtual => call Class 3 virtual => call Class 4 constructor
Great job sbx320, your lib is very usefull for me. I saw function addChangeHandler at wiki, but cant find it in current sources. May be, is equivalent exists now?
Hello! You can add a wiki using your classlib?
Thx
Reproduce with
Foo = { bar = 12 }
addChangeHandler(Foo, print)
Foo.bar = 1
Expected result would be an output.
This is caused by __newindex not being called on existing keys
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.