Original Post
Hello, I'm trying to register some classes for AngelScript, but I'm receiving some very vague error messages. I'd like to register my 'property' class which handles the different properties/settings for my program. In CPP, I can do the following thing: Here's the source code for the property class. Maybe it isn't a very nice solution, but this way I don't need to have a property instance for every property. I'm not sure how I should register this for AngelScript, but I thought that since the class only has 1 string member, it should be a value type. I also thought I only needed to register a constructor and a assignment behavior, so here's how I register it (as_check checks the return value, m_as is a pointer to asIScriptEngine): When I execute this (AS): I get the following error message:
property("test") = "bla";
...
std::cout << property("test").value(); // prints out 'bla'
#include <string>
#include <boost/unordered_map.hpp>
class property {
public:
property(std::string name) : m_name(name) { }
void operator=(const std::string value)
{
m_hashmap[m_name] = value;
}
void set(const std::string value)
{
operator=(value);
}
std::string value() const
{
return m_hashmap[m_name];
}
private:
std::string m_name;
static boost::unordered_map<std::string, std::string> m_hashmap;
};
void new_property(std::string name, property *memory)
{
new(memory) property(name);
}
...
as_check(m_as->RegisterObjectType("property", sizeof(property), asOBJ_VALUE | asOBJ_APP_CLASS_CA));
as_check(m_as->RegisterObjectBehaviour("property", asBEHAVE_CONSTRUCT, "void f(const string)", asFUNCTION(new_property), asCALL_CDECL_OBJLAST));
as_check(m_as->RegisterObjectBehaviour("property", asBEHAVE_ASSIGNMENT, "void f(const string)", asMETHOD(property, set), asCALL_THISCALL));
void main()
{
property("test") = "42";
}
Quote:which isn't helping me a lot. So I'm wondering what I'm doing wrong. I've looked at the documentation and the vector-addon, but I don't know what's causing the problem.
Error (line 0, col 0): Type 'property' is missing behaviours Error (line 0, col 0): Invalid configuration