These are chat archives for ChaiScript/ChaiScript

May 2019
Addison Schuhardt
May 05 22:02

@RubenReijers yes it does. But it was only added to the develop branch recently. You can do the following when TerrainType is an enum class:

chaiscript::ModulePtr m = chaiscript::ModulePtr(new chaiscript::Module());
  { { TerrainType::SOIL, "SOIL" },
    {TerrainType::PASSABLE, "PASSABLE"},
    { TerrainType::STONE, "STONE" }

Is it still possible to use enum classes this way in the current development branch?

I've tried this same method as follows:
  auto key_module = std::make_shared<chaiscript::Module>();
      *key_module, "Key",
          {Key::N0, "KEY_N0"},
          {Key::N1, "KEY_N1"},
          {Key::N2, "KEY_N2"},
          {Key::N3, "KEY_N3"},
          {Key::N4, "KEY_N4"},
I'm not sure how I'm supposed to access these values however.
I've tried
  var k = Key();
But I get the error message terminate called after throwing an instance of 'chaiscript::exception::eval_error' what(): Error: "Error with function dispatch for function 'to_string'" With parameters: (Key).()
trying to access the class's attr by value var x = k.KEY_N0; throws another error
Error: "'KEY_N0' is not a function."
Maybe I'm misunderstanding what the add_class utility is supposed to be doing?
Addison Schuhardt
May 05 22:09
var k = Key.KEY_N0 throws this error:
Error: "Error with function dispatch for function 'KEY_N0'" With parameters: (const Function).(string)
What am I missing?
Addison Schuhardt
May 05 22:18
Welp. Figured it out. It adds global(?) constants. This works:
var k = KEY_N0;
in case anyone has the same question