Comments (5)
Attached please see a modified test/exampels/simple.cpp. The key is to give the name of metaclass that is not the same as the metaclass's C++ type name. For example, in this example I gave the name of the Person metaclass "People". After you re-make simple.cpp and run it, you should see the following exception raised.
test/examples/simple.cpp:112: FAILED:
due to unexpected exception with message:
the metaclass Person couldn't be found
from ponder.
Do you have an example of this failing please? The unit tests seem to work: https://github.com/billyquith/ponder/blob/master/test/ponder/class.cpp
from ponder.
simple.cpp.txt:
#include "test.hpp"
//! [eg_simple]
#include <ponder/classbuilder.hpp>
#include <ponder/uses/runtime.hpp>
#include <iostream>
//! [eg_simple_class]
class Person
{
public:
// constructor
Person(const std::string& name)
: m_name(name)
{}
// accessors for private members
std::string name() const { return m_name; }
void setName(const std::string& name) { m_name = name; }
// public members
float height;
unsigned int shoeSize;
// member function
bool hasBigFeet() const { return shoeSize > 10; } // U.K.!
private:
std::string m_name;
};
//! [eg_simple_class]
//! [eg_simple_declare]
PONDER_TYPE(Person) // declare the type to Ponder
static void declare() // declare the class members to Ponder
{
ponder::Class::declare<Person>("People")
.constructor<std::string>()
.property("name", &Person::name, &Person::setName)
.property("height", &Person::height)
.property("shoeSize", &Person::shoeSize)
.function("hasBigFeet", &Person::hasBigFeet)
;
}
//! [eg_simple_declare]
//! [eg_simple_use]
// An example of how you might use Ponder:
static void use()
{
//! [eg_simple_metaclass]
// retrieve the metaclass (containing the member data)
const ponder::Class& metaclass = ponder::classByName("People");
//! [eg_simple_metaclass]
//! [eg_simple_create]
// construct a new person
ponder::UserObject person = ponder::runtime::create(metaclass, "Bozo");
//! [eg_simple_create]
// 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>();
// nasty
//! [eg_simple_destroy]
ponder::runtime::destroy(person);
//! [eg_simple_destroy]
}
//! [eg_simple_use]
//! [eg_simple]
from ponder.
Ok, yes this needs some work.
from ponder.
return UserObject(&classByObject(object), new Holder(RefTraits::getPointer(object)));
from UserObject UserObject::makeRef(T& object)
is the problem. classByName()
isn't the problem, it is makeRef() trying to get the metaclass details via the object type, which is different. Probably best to look up everything by type (id) and map the names instead. This could mean substantial changes to the registration/declaration.
from ponder.
Related Issues (20)
- Failed to build Lua example HOT 3
- ponder::Value's comparison operators are not complete HOT 4
- missing a return statement in string_view.hpp at line 215 HOT 1
- classByType<std::string> throws classNotFound HOT 26
- call by reference, using a pointer or a non-const reference, does not work HOT 18
- Having problems to get the property value of a user defined type HOT 6
- Interest for registration of template types? HOT 4
- Deprecate MSVC 2015 HOT 1
- support inherit for lua?
- Class properties do not respect ValueMappers HOT 1
- How to properly set nested UserObjects? HOT 1
- Ponder compile failed with a future version of MSVC HOT 6
- Building Error HOT 1
- Replace exceptions with tryGet
- Use runtime error HOT 2
- Destroy object causes a runtime failure
- How to build and user ponder with windows7? HOT 3
- Execute function of class by class name as string
- Unable to compile under ubuntu 22.04 LTS without two file changes in util.cpp and catch.hpp
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ponder.