From 4ece07fafb08b739675f306add1909d40c43aafb Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Mon, 17 Jun 2024 12:37:24 -0500 Subject: [PATCH 1/3] Avoid Dynamic example in DynamicAccess I think using a type param other than Dynamic makes it more clear what the type param is actually used for --- assets/DynamicAccess.hx | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/assets/DynamicAccess.hx b/assets/DynamicAccess.hx index 90f13135..80c83a0f 100644 --- a/assets/DynamicAccess.hx +++ b/assets/DynamicAccess.hx @@ -1,16 +1,27 @@ -class Main { - static public function main() { - var user:haxe.DynamicAccess = {}; +class Test { + static function main() { + var users:haxe.DynamicAccess = { + John: { surname: "Smith", age: 24 }, + Patti: { surname: "Mayonaise", age: 16 } + }; - // Sets values for specified keys. - user.set("name", "Mark"); - user.set("age", 25); + // Get user John, throw him a brithday + var john = users.get("John"); + john.age++; - // Returns values by specified keys. - trace(user.get("name")); // "Mark" - trace(user.get("age")); // 25 + trace('$name ${john.surname} is ${john.age} years old'); // John Smith is 25 years old - // Tells if the structure contains a specified key - trace(user.exists("name")); // true - } + // Add new user + users.set("Mark", { surname: "McCartney", age:30 }); + + // Whether the structure contains a specified key + trace(user.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 }; From 5cfba8ab3c0dde63758d1ae305ac425303a0a7c2 Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Mon, 17 Jun 2024 12:41:42 -0500 Subject: [PATCH 2/3] typos --- assets/DynamicAccess.hx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/assets/DynamicAccess.hx b/assets/DynamicAccess.hx index 80c83a0f..6c40c884 100644 --- a/assets/DynamicAccess.hx +++ b/assets/DynamicAccess.hx @@ -4,19 +4,19 @@ class Test { 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('$name ${john.surname} is ${john.age} years old'); // John Smith is 25 years old - + + trace('John ${john.surname} turned ${john.age}'); + // Add new user users.set("Mark", { surname: "McCartney", age:30 }); - - // Whether the structure contains a specified key - trace(user.exists("Mark")); // true - + + // 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'); From bceb3f922ec697ed539e5527cee871c30fe3f904 Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Mon, 17 Jun 2024 12:43:01 -0500 Subject: [PATCH 3/3] show output --- assets/DynamicAccess.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/DynamicAccess.hx b/assets/DynamicAccess.hx index 6c40c884..e1220ab7 100644 --- a/assets/DynamicAccess.hx +++ b/assets/DynamicAccess.hx @@ -9,7 +9,7 @@ class Test { var john = users.get("John"); john.age++; - trace('John ${john.surname} turned ${john.age}'); + trace('John ${john.surname} turned ${john.age}'); // John Smith turned 25 // Add new user users.set("Mark", { surname: "McCartney", age:30 });