| 4 | #include <iostream> |
| 5 | |
| 6 | int main() { |
| 7 | std::cout << "=== override-able member functions ===" |
| 8 | << std::endl; |
| 9 | |
| 10 | struct thingy { |
| 11 | sol::function paint; |
| 12 | |
| 13 | thingy(sol::this_state L) |
| 14 | : paint(sol::make_reference<sol::function>( |
| 15 | L.lua_state(), &thingy::default_paint)) { |
| 16 | } |
| 17 | |
| 18 | void default_paint() { |
| 19 | std::cout << "p" << std::endl; |
| 20 | } |
| 21 | }; |
| 22 | |
| 23 | sol::state lua; |
| 24 | lua.open_libraries(sol::lib::base); |
| 25 | |
| 26 | lua.new_usertype<thingy>("thingy", |
| 27 | sol::constructors<thingy(sol::this_state)>(), |
| 28 | "paint", |
| 29 | &thingy::paint); |
| 30 | |
| 31 | sol::string_view code = R"( |
| 32 | obj = thingy.new() |
| 33 | obj:paint() |
| 34 | obj.paint = function (self) print("g") end |
| 35 | obj:paint() |
| 36 | function obj:paint () print("s") end |
| 37 | obj:paint() |
| 38 | )"; |
| 39 | |
| 40 | lua.safe_script(code); |
| 41 | |
| 42 | std::cout << std::endl; |
| 43 | |
| 44 | return 0; |
| 45 | } |
nothing calls this directly
no test coverage detected