Bonus Posted November 16, 2017 Share Posted November 16, 2017 Hey, I always wondered why there is this information: "The function is called with the query handle as the first argument. (Notice: Do not use a function with a local prefix)" Here:https://wiki.multitheftauto.com/wiki/DbQuery I've never had any problems with local functions in dbQuery. Is the notice old or is there something I don't know? Link to comment
John Smith Posted November 17, 2017 Share Posted November 17, 2017 Probably because callback functions aren't called instantly, rather it waits for result, and after your function finishes that code, everything that was declared local inside of that function will be erased from memory automatically, thus making your local callback function non-existant and so you'll never recieve result from dbQuery Link to comment
Bonus Posted November 18, 2017 Author Share Posted November 18, 2017 Sry, but I'm absolutely sure that's not the case. The garbage collector in Lua isn't that stupid. Also a local table would get erased, too, because it get's passed by reference like a function. But we can use tables to pass optional parameters in dbQuery, that's why your idea is impossible. Link to comment
Moderators IIYAMA Posted November 19, 2017 Moderators Share Posted November 19, 2017 It should be indeed not a problem. But keep in mind that once the function with a callback has been executed, it leaves the lua environment. If MTA doesn't tell lua to keep that function then the garbage collector loves to clean it. If you want to know this for sure, you can manually collect it and see if an error appears. It is probably old information if you ask me. Link to comment
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