![]() |
Function Closures!
I've requested this once before, but I really think this should happen. Currently we have anonymous functions, but they are a slight pain to use, because you can't use variables defined outside of the function without explicitly passing them in.
Function closures are when the environment outside of the anon functions are "closed" inside of them, letting you use the variables defined outside of the anon functions inside of them. Extremely simple example: PHP Code:
Note: You can set this variables to pass things in, but then you need to handle all the garbage collection yourself because the anonymous function can still exist after the surrounding function ends (i.e., by returning it). This is basically impossible since you don't know when the function is destroyed. It's also really messy and ugly. An example where this would be useful: PHP Code:
When you chat "10", that should echo out "10,20,30,40". |
It would be neat if we could get this, so GS2 could move slightly out of the category of 'old and grungy looking' and into the category of 'polished and interesting', in terms of programming languages.
C#, Lua, Perl, PHP, Python, Java, JavaScript, and more, all have closures. |
:0 this sounds like an awesome idea, could we have the ability to call functions from other classes as well?
example:system.map(bla); |
Quote:
There are many interesting 'general purpose' functions like map which can be stored in a separate weapon to make your life easier. (In fact, I've already implemented a bunch of them, they just aren't as useful as they should be since we don't have closures). |
| All times are GMT +2. The time now is 01:59 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.