digitalmars.D.learn - Are Lua tables possible to do with D?
- =?iso-8859-1?Q?Robert_M._M=FCnch?= (9/9) Jul 15 2015 Hi, do you think it's possible to implemented something like Lua Tables
- Fusxfaranto (4/9) Jul 16 2015 An associative array of Variant[string] ought to do the job well
- =?iso-8859-1?Q?Robert_M._M=FCnch?= (6/9) Jul 16 2015 Thanks a lot. Somehow didn't see that...
- rcorre (23/26) Jul 17 2015 For extra fun, you can implement the '.' style syntax pretty
- Jesse Phillips (5/10) Jul 16 2015 Check out LuaD[1], it is more about conversions, but you can
Hi, do you think it's possible to implemented something like Lua Tables (a hashed heterogeneous associative array) in D? I know that Lua is dynamic and interpreted, hence it's a lot simpler to do than with a compiled language but I'm wondering if we could express such a generic data-structure in D. -- Robert M. Münch http://www.saphirion.com smarter | better | faster
Jul 15 2015
On Thursday, 16 July 2015 at 06:48:12 UTC, Robert M. Münch wrote:Hi, do you think it's possible to implemented something like Lua Tables (a hashed heterogeneous associative array) in D? I know that Lua is dynamic and interpreted, hence it's a lot simpler to do than with a compiled language but I'm wondering if we could express such a generic data-structure in D.An associative array of Variant[string] ought to do the job well enough. http://dlang.org/phobos/std_variant.html
Jul 16 2015
On 2015-07-16 07:20:15 +0000, Fusxfaranto said:An associative array of Variant[string] ought to do the job well enough. http://dlang.org/phobos/std_variant.htmlThanks a lot. Somehow didn't see that... -- Robert M. Münch http://www.saphirion.com smarter | better | faster
Jul 16 2015
On Thursday, 16 July 2015 at 07:20:16 UTC, Fusxfaranto wrote:An associative array of Variant[string] ought to do the job well enough. http://dlang.org/phobos/std_variant.htmlFor extra fun, you can implement the '.' style syntax pretty easily: --- import std.variant; struct LuaTable { Variant[string] _table; alias _table this; auto opDispatch(string s)() { return _table[s]; } void opDispatch(string s, T)(T val) { _table[s] = Variant(val); } } unittest { LuaTable table; table.foo = 5; table.bar = "s"; assert(table.foo == 5); assert(table.bar == "s"); } ---
Jul 17 2015
On Thursday, 16 July 2015 at 06:48:12 UTC, Robert M. Münch wrote:Hi, do you think it's possible to implemented something like Lua Tables (a hashed heterogeneous associative array) in D? I know that Lua is dynamic and interpreted, hence it's a lot simpler to do than with a compiled language but I'm wondering if we could express such a generic data-structure in D.Check out LuaD[1], it is more about conversions, but you can convert to a algebraic structure, I need to revisit this now that Algebraic types can be self referencing. 1. https://github.com/JakobOvrum/LuaD
Jul 16 2015