|
@@ -3,10 +3,12 @@
|
|
|
|
|
|
|
|
#include <iostream>
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
+using namespace luwra;
|
|
|
|
|
+
|
|
|
struct Point {
|
|
struct Point {
|
|
|
- lua_Number x, y;
|
|
|
|
|
|
|
+ double x, y;
|
|
|
|
|
|
|
|
- Point(lua_Number x, lua_Number y):
|
|
|
|
|
|
|
+ Point(double x, double y):
|
|
|
x(x), y(y)
|
|
x(x), y(y)
|
|
|
{
|
|
{
|
|
|
std::cout << "Construct Point(" << x << ", " << y << ")" << std::endl;
|
|
std::cout << "Construct Point(" << x << ", " << y << ")" << std::endl;
|
|
@@ -16,7 +18,7 @@ struct Point {
|
|
|
std::cout << "Destruct Point(" << x << ", " << y << ")" << std::endl;
|
|
std::cout << "Destruct Point(" << x << ", " << y << ")" << std::endl;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- void scale(lua_Number f) {
|
|
|
|
|
|
|
+ void scale(double f) {
|
|
|
x *= f;
|
|
x *= f;
|
|
|
y *= f;
|
|
y *= f;
|
|
|
}
|
|
}
|
|
@@ -33,22 +35,22 @@ int main() {
|
|
|
// Register our user type.
|
|
// Register our user type.
|
|
|
// This function also registers a garbage-collector hook and a string representation function.
|
|
// This function also registers a garbage-collector hook and a string representation function.
|
|
|
// Both can be overwritten using the third parameter, which lets you add custom meta methods.
|
|
// Both can be overwritten using the third parameter, which lets you add custom meta methods.
|
|
|
- luwra::register_user_type<Point>(
|
|
|
|
|
|
|
+ RegisterUserType<Point>(
|
|
|
state,
|
|
state,
|
|
|
// Methods which shall be availabe in the Lua user data, need to be declared here
|
|
// Methods which shall be availabe in the Lua user data, need to be declared here
|
|
|
{
|
|
{
|
|
|
- {"scale", luwra::WrapMethod<Point, void(lua_Number), &Point::scale>},
|
|
|
|
|
|
|
+ {"scale", WrapMethod<Point, void(double), &Point::scale>},
|
|
|
},
|
|
},
|
|
|
// Meta methods may be registered aswell
|
|
// Meta methods may be registered aswell
|
|
|
{
|
|
{
|
|
|
- {"__tostring", luwra::WrapMethod<Point, std::string(), &Point::toString>}
|
|
|
|
|
|
|
+ {"__tostring", WrapMethod<Point, std::string(), &Point::toString>}
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
// What's left, is registering a constructor for our type.
|
|
// What's left, is registering a constructor for our type.
|
|
|
// We have to specify which parameters our constructor takes, because there might be more than
|
|
// We have to specify which parameters our constructor takes, because there might be more than
|
|
|
// one constructor to deal with.
|
|
// one constructor to deal with.
|
|
|
- auto wrapped_ctor = luwra::WrapConstructor<Point, lua_Number, lua_Number>;
|
|
|
|
|
|
|
+ auto wrapped_ctor = WrapConstructor<Point, double, double>;
|
|
|
lua_pushcfunction(state, wrapped_ctor);
|
|
lua_pushcfunction(state, wrapped_ctor);
|
|
|
lua_setglobal(state, "Point");
|
|
lua_setglobal(state, "Point");
|
|
|
|
|
|