| 49 | }; |
| 50 | |
| 51 | int main() { |
| 52 | std::cout << "=== usertype_initializers ===" << std::endl; |
| 53 | { // additional scope to make usertype destroy earlier |
| 54 | sol::state lua; |
| 55 | lua.open_libraries(); |
| 56 | |
| 57 | lua.new_usertype<holy>("holy", |
| 58 | "new", |
| 59 | sol::initializers(&holy::initialize), |
| 60 | "create", |
| 61 | sol::factories(&holy::create), |
| 62 | sol::meta_function::garbage_collect, |
| 63 | sol::destructor(&holy::destroy), |
| 64 | "data", |
| 65 | &holy::data); |
| 66 | |
| 67 | lua.script(R"( |
| 68 | h1 = holy.create() |
| 69 | h2 = holy.new() |
| 70 | print('h1.data is ' .. h1.data) |
| 71 | print('h2.data is ' .. h2.data) |
| 72 | )"); |
| 73 | holy& h1 = lua["h1"]; |
| 74 | holy& h2 = lua["h2"]; |
| 75 | SOL_ASSERT(h1.data == 50); |
| 76 | SOL_ASSERT(h2.data == 0); |
| 77 | } |
| 78 | std::cout << std::endl; |
| 79 | } |
nothing calls this directly
no test coverage detected