billyquith / ponder

C++ reflection library with Lua binding, and JSON and XML serialisation.
http://billyquith.github.io/ponder/
Other
645 stars 95 forks source link

Execute function of class by class name as string #128

Open paulocoutinhox opened 2 years ago

paulocoutinhox commented 2 years ago

Hi,

Im checking your example:

// retrieve the metaclass (containing the member data)
const ponder::Class& metaclass = ponder::classByType<Person>();

// construct a new person
ponder::UserObject person = ponder::runtime::create(metaclass, "Bozo");

// set attributes
person.set("height", 1.62f);
person.set("shoeSize", 28);

// retrieve a function we would like to call
const auto& func = metaclass.function("hasBigFeet");

// call the function and get the result
const bool bigFeet = ponder::runtime::call(func, person).to<bool>();

But in my case, i want something like this:

const ponder::Class& metaclass = ponder::classByString("Person");
ponder::UserObject person = ponder::runtime::create(metaclass, "Bozo");
const auto& func = metaclass.function("hasBigFeet");
const bool bigFeet = ponder::runtime::call(func, person).to<bool>();

And the second question is how to create using namespace, example:

namespace xyz {
    class Person {};
}

const ponder::Class& metaclass = ponder::classByString("xyz::Person");
ponder::UserObject person = ponder::runtime::create(metaclass, "Bozo");
const auto& func = metaclass.function("hasBigFeet");
const bool bigFeet = ponder::runtime::call(func, person).to<bool>();

Thanks.