int main(int argc, char* argv[]) { // create a new Lua state. lua_State* L = luaL_newstate(); // load Lua libraries std::vector<luaL_Reg> lualibs = { {"base", luaopen_base} , {"io", luaopen_io} }; for(auto& it : lualibs) { // load the required lua libs and store it in the global space. luaL_requiref(L, it.name, it.func, 1); // clear the stack in case there is some remaining stuffs there. lua_settop(L, 0); } // load the script int status = luaL_loadfile(L, "function.lua"); if(status == 0) // okay { std::cout << "[C++] script loaded" << std::endl; } else { std::cout << "[C++] error loading script" << std::endl; return 1; } int result = result = lua_pcall(L, 0, LUA_MULTRET, 0); if(status == LUA_OK) { } else { std::cout << "[C++] Could not run the script." << std::endl; return 1 ; } doThings(L); lua_close(L); return 0; }
void test_doThings(void) { ErrorObject *err; Try { doThings(); TEST_FAIL_MESSAGE("Expect ERR_DUNNO_WHAT_HAPPEN to be thrown." \ "But none throw."); } Catch(err) { TEST_ASSERT_EQUAL_STRING("Hey! Something is really wrong here.", \ err->errorMsg); TEST_ASSERT_EQUAL(ERR_DUNNO_WHAT_HAPPEN, err->errorCode); freeError(err); } }
int main(int argc, char* argv[]) { // create a new Lua state. lua_State* L = luaL_newstate(); // load Lua libraries std::vector<luaL_Reg> lualibs = { {"base", luaopen_base} , {"io", luaopen_io} }; for(auto& it : lualibs) { // load the required lua libs and store it in the global space. luaL_requiref(L, it.name, it.func, 1); // clear the stack in case there is some remaining stuffs there. lua_settop(L, 0); } doThings(L); lua_close(L); return 0; }