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.html

For 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");
}
---

Reply via email to