Jump to content

local function


Drakath

Recommended Posts

Posted

I don't know if it's more efficient, but it can be useful if you want two functions using the same name in two different script files within the same resource to do different things.

Posted
Yeah, I know but I heard that using local makes it faster and uses less memory or something. I wonder if that's true.

Yes, accessing local variables/functions is faster than global.

Posted

Local variables (this includes functions, because they're stored in variables too - function foo () is syntatic sugar for foo = function()) are indeed faster to access because they're stored on the stack. On the other hand, to access globals you must do a hash table lookup (in the environment table).

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...