int main(int argc, char **argv) { static GameState state = {NULL, NULL}; setjmp(resetbuf); init_state(&state); if (runlua(&state, "boot.lua")) { luareport(&state); } return 0; }
void runtest (void) { lua::State L; L.loadlib (luaopen_base, ""); lua::register_class<Object> (L, "Object"); lua::register_class<Test> (L, "Test"); runlua (L, "function check (value, message) assert (value, message) print (message..': passed') end"); runlua (L, "test = Test() check (test.F1() == 101, 'return int by value')" "check (test.F2() == 102, 'return int by const reference')" "check (test.F3() == 103, 'return int by reference')" "check (test.F4() == 104, 'return int by rvalue reference')" "check (test.F5() == 'F5', 'return string by value')" "check (test.F6() == 'F6', 'return string by reference')" "check (test.F7() == 'F7', 'return string by const reference')" "check (test.F8() == 'F8', 'return string by rvalue reference')" "check (test.F9() == 'F9', 'return string by rvalue reference')"); runlua (L, "obj = test.F10 ()"); lua_getglobal (L, "obj"); check (getobj (L)->checkstate (MOVE, false, false, 53) && Object::count == 2, "return object by value"); Object::count = 0; runlua (L, "obj = test.F11 ()"); check (getobj (L)->checkstate (COPY, false, false, 54) && Object::count == 2, "return object by const reference"); Object::count = 0; runlua (L, "obj = test.F12 ()"); check (getobj (L)->checkstate (COPY, false, false, 55) && Object::count == 2, "return object by reference"); Object::count = 0; runlua (L, "obj = test.F13 ()"); check (getobj (L)->checkstate (MOVE, false, false, 56) && Object::count == 2, "return object by rvalue reference"); Object::count = 0; runlua (L, "obj = test.F14 ()"); check (getobj (L)->checkstate (EXPLICIT, false, false, 57) && Object::count == 1, "return object by pointer"); Object::count = 0; runlua (L, "obj = test.F15 ()"); check (getobj (L)->checkstate (EXPLICIT, false, false, 58) && Object::count == 1, "return object by const pointer"); }