![]() |
Multi-Dimensional Arrays
It would be great if there was a way to get all index out of a multi-dimensional array. I don't really know how to word this ...
For example, PHP Code:
PHP Code:
|
Not entirely sure, but just a note, it would probably make more sense to use a hash (TStaticVar/TGraalVar) in this case:
PHP Code:
|
Quote:
|
Typically in languages like PHP, an associative array would be used for this purpose ($staff["Skyld"] = "Global Scripting Admin";) except GScript does not sport this functionality. About the best I can suggest is to use a TStaticVar-esque table like WhiteDragon suggested, since it's about the closest to an associative array as you'll get in GScript.
|
I expect that a hash table is used for storing the variables of an object, so a TStaticVar is a good choice in that situation.
As I was typing that I just had an idea about associative arrays. I think that in the case of an object, 'a["b"]' would map to 'a.b'. This would allow people to use a more appropriate syntax so it is obvious the coder is using the object as an associative array. In the case where b is a number, it would map to 'a.index<b>' (without brackets). Example: staff = new TStaticVar(); staff.timeout = 5; staff["timeout"] = 5; // same as the previous staff.(@ "lol" @ 3) = "pancake"; staff["lol" @ 3] = "pancake"; // same as the previous, but clearer (imho) staff[5] = "five"; echo("5: " @ staff.index5); // example of how number is mapped to variable name |
I'm not a really a fan of the syntax you're suggesting Inverness. All subvariables are referenced the same way with all the objects, there is no reason to adopt that syntax simply because a few other languages use it.
Technically an Array is a subtype of a TStaticVar already, although I'm not sure if the engine changes how it handles them (hash, linked list, etc). I'm not sure if you could still access the variables with the subvariable syntax either, but their might be a (undocumented) way to. |
I made a thread about the same thing last week. :oo:
http://forums.graalonline.com/forums...ad.php?t=83824 |
Quote:
The new syntax would show how you intend to use the object. If we did it like this, then I would never have to use the ugly var.(@ "something") because you have a more proper way to mimic dynamic variables. |
Quote:
Quote:
Quote:
Quote:
|
Quote:
Are you complaining about the syntax itself, or the suggestion? |
Quote:
An associative array is a mapping of series of keys to their values, which happens to be what a hash does. The way Graal chooses to handle this is with subvariables. Introducing the alternate syntax would only make things more confusing and suggest that there is actually a difference between the syntaxes when there isn't. |
Quote:
My suggestion was simply the easiest way to implement an associative array facade, of course I don't expect that to be implemented either. |
Quote:
|
Quote:
*shrug* It's not really important, was just a random idea. |
Quote:
|
Quote:
|
Quote:
|
Quote:
|
Quote:
Edit: I am not sure anymore what you are refering to. Lua at least lets you do getfenv(1)[varname] = 42, equivalent to local varname = 42, I think. |
Quote:
|
| All times are GMT +2. The time now is 05:02 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.