mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
92a6fb8c11
fix implicitly convertible function pointers from classes using `call_detail`'s `lua_call_wrapper` specificaly add documentation for working with `std::function`
35 lines
522 B
C++
35 lines
522 B
C++
#define SOL_CHECK_ARGUMENTS 1
|
|
#include <sol.hpp>
|
|
|
|
#include <cassert>
|
|
|
|
int main() {
|
|
struct my_class {
|
|
int b = 24;
|
|
|
|
int f() const {
|
|
return 24;
|
|
}
|
|
|
|
void g() {
|
|
++b;
|
|
}
|
|
};
|
|
|
|
sol::state lua;
|
|
lua.open_libraries();
|
|
|
|
sol::table bark = lua.create_named_table("bark");
|
|
bark.new_usertype<my_class>("my_class",
|
|
"f", &my_class::f,
|
|
"g", &my_class::g
|
|
); // the usual
|
|
|
|
lua.script("obj = bark.my_class.new()"); // this works
|
|
lua.script("obj:g()");
|
|
my_class& obj = lua["obj"];
|
|
assert(obj.b == 25);
|
|
|
|
return 0;
|
|
}
|