Convention name for registering namespaced classes


#1

Hi,

I having a hard time naming classes correctly. I’ve got the following in C++. How would one register the "Type" class so that its namespace is not lost?

namespace Configuration { class Type {}; }

I actually gave "Configuration::Type" a go, but it seems :: is not really supported. Ideally, I’d really like to refer to this class, in the script, as "Configuration::Type". It’s a pity that is not supported.

What are the options here? Is there any already-defined convention on this matter? Should i be "ConfigurationType", or "Configuration_Type"? Is there anything else that can be done to improve usability?

Thanks,

G


#2

You’ll have to add the namespace, and then declare a function within the namespace to initialize an object of type Type.

// Register the namespace
chai.register_namespace([](chaiscript::Namespace& config) {
  config["Type"] = fun(&Configuration::CreateType);
}, "Configuration");

// Import the Configuration namespace
chai.import("Configuration");

In ChaiScript, using it would look like…

var myConfig = Configuration.Type("Some", "Args")

Could also try to scope the Type within the Configuration namespace.