bool LuaContext::do_file_if_exists(lua_State* l, const std::string& script_name) { if(load_file_if_exists(l, script_name)) { call_function(l, 0, 0, script_name); return true; } return false; }
/** * \brief Implementation of sol.main.load_file(). * \param l The Lua context that is calling this function. * \return Number of values to return to Lua. */ int LuaContext::main_api_load_file(lua_State *l) { const std::string& file_name = luaL_checkstring(l, 1); if (!load_file_if_exists(l, file_name)) { lua_pushnil(l); } return 1; }
/** * @brief A loader that makes require() able to load Lua files * from the quest data directory or archive. * @param l The Lua context. * @return Number of values to return to Lua. */ int LuaContext::l_loader(lua_State* l) { const std::string& script_name = luaL_checkstring(l, 1); bool exists = load_file_if_exists(l, script_name); if(!exists) { std::cerr << "No quest file.\n"; } return 1; }