We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
class person { public: person() : name("Tom"), age(0) { } virtual~person() = default; person* set_name(const std::string& name) { this->name = name; return this; } person* set_age(unsigned int age) { this->age = age; return this; } const std::string& get_name() const{ return this->name; } unsigned int get_age() { return this->age; } private: std::string name; unsigned int age; }; class studest : public person { public: studest() : person() { } virtual~studest() = default; double get_score() { return this->score; } studest* set_score(double score) { this->score = score; return this; } private: double score; };
vm["person"]=kaguya::UserdataMetatable<person>() .setConstructors < person()>() .addFunction("get_age", &person::get_age) .addFunction("get_name", &person::get_name) .addFunction("set_age", &person::set_age) .addFunction("set_name", &person::set_name) vm["studest"]=kaguya::UserdataMetatable<studest, person>() .setConstructors < studest()>() .addFunction("get_score", &studest::get_score) .addFunction("set_score", &studest::set_score);
local s=studest.new() s:set_score(74.6):set_name("Jerry"):set_age(14)
The above example sucessfully.
local s=studest.new() s:set_name("Jerry"):set_age(14):set_score(40)
The above example failed.
class studest; class person { public: person() : name("Tom"), age(0) { } virtual~person() = default; studest* set_name(const std::string& name) { this->name = name; return reinterpret_cast<studest*>(this); } studest* set_age(unsigned int age) { this->age = age; return reinterpret_cast<studest*>(this); } const std::string& get_name() const{ return this->name; } unsigned int get_age() { return this->age; } private: std::string name; unsigned int age; };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The above example sucessfully.
The above example failed.
If the modified class is defined as follows, both examples are successful:
The text was updated successfully, but these errors were encountered: