Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions assets/DynamicAccess.hx
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
class Main {
static public function main() {
var user:haxe.DynamicAccess<Dynamic> = {};

// Sets values for specified keys.
user.set("name", "Mark");
user.set("age", 25);

// Returns values by specified keys.
trace(user.get("name")); // "Mark"
trace(user.get("age")); // 25

// Tells if the structure contains a specified key
trace(user.exists("name")); // true
}
class Test {
static function main() {
var users:haxe.DynamicAccess<User> = {
John: { surname: "Smith", age: 24 },
Patti: { surname: "Mayonaise", age: 16 }
};

// Get user John, throw him a brithday
var john = users.get("John");
john.age++;

trace('John ${john.surname} turned ${john.age}'); // John Smith turned 25

// Add new user
users.set("Mark", { surname: "McCartney", age:30 });

// Whether the structure contains a specified key
trace(users.exists("Mark")); // true

// Output all users
for (name => data in users) {
trace('$name ${data.surname} is ${data.age} years old');
}
}
}

typedef User = { surname:String, age:Int };