Jump to content

dbQuery - why not use local function?


Bonus

Recommended Posts

Posted

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?

Posted

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

Posted

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.

  • Moderators
Posted

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.

 

 

 

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...