2019-05-22 07:17:31 +08:00
|
|
|
#define SOL_ALL_SAFETIES_ON 1
|
2018-02-25 06:19:16 +08:00
|
|
|
|
2018-09-28 13:27:38 +08:00
|
|
|
#include <sol/sol.hpp>
|
2018-02-25 06:19:16 +08:00
|
|
|
|
|
|
|
struct vars {
|
|
|
|
int boop = 0;
|
|
|
|
|
2021-03-06 14:03:23 +08:00
|
|
|
int bop() const {
|
2018-02-25 06:19:16 +08:00
|
|
|
return boop + 1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
sol::state lua;
|
2021-03-06 23:14:48 +08:00
|
|
|
lua.new_usertype<vars>(
|
|
|
|
"vars", "boop", &vars::boop, "bop", &vars::bop);
|
2021-03-06 14:03:23 +08:00
|
|
|
lua.script(
|
|
|
|
"beep = vars.new()\n"
|
|
|
|
"beep.boop = 1\n"
|
|
|
|
"bopvalue = beep:bop()");
|
2018-02-25 06:19:16 +08:00
|
|
|
|
|
|
|
vars& beep = lua["beep"];
|
|
|
|
int bopvalue = lua["bopvalue"];
|
|
|
|
|
2022-09-28 13:56:26 +08:00
|
|
|
SOL_ASSERT(beep.boop == 1);
|
|
|
|
SOL_ASSERT(lua.get<vars>("beep").boop == 1);
|
|
|
|
SOL_ASSERT(beep.bop() == 2);
|
|
|
|
SOL_ASSERT(bopvalue == 2);
|
2018-02-25 06:19:16 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|