/** * @brief Attempts to compile a Lua script. * * @param filename Filename of the script. * @param buffer The buffer to store the script's compiled bytecode. * * @return true if it succeeds, false if it fails. */ bool CLuaScript::CompileScript(const char * filename, BytecodeBuffer & buffer) { // ensure that we wait until the last user's done executing their script. Guard lock(m_lock); /* Attempt to load the file */ int err = luaL_loadfile(m_luaState, filename); // If something bad happened, try to find an error. if (err != LUA_OK) { RetrieveLoadError(err, filename); return false; } // Everything's OK so far, the script has been loaded, now we need to start dumping it to bytecode. err = lua_dump(m_luaState, (lua_Writer)LoadBytecodeChunk, &buffer); if (err || buffer.empty()) { printf("ERROR: Failed to dump the Lua script `%s` to bytecode.\n", filename); return false; } // Compiled! return true; }
/** * @brief Attempts to compile a Lua script. * * @param filename Filename of the script. * @param buffer The buffer to store the script's compiled bytecode. * * @return true if it succeeds, false if it fails. */ bool CLuaScript::CompileScript(const char * filename, BytecodeBuffer & buffer) { // ensure that we wait until the last user's done executing their script. FastGuard lock(m_lock); /* Attempt to load the file */ int err = luaL_loadfile(m_luaState, filename); // If something bad happened, try to find an error. if (err != LUA_OK) { RetrieveLoadError(err, filename); return false; } // Everything's OK so far, the script has been loaded, now we need to start dumping it to bytecode. err = lua_dump(m_luaState, (lua_Writer)LoadBytecodeChunk, &buffer); if (err || buffer.empty()) { printf("ERROR: Failed to dump the Lua script `%s` to bytecode.\n", filename); return false; } #if !defined(USE_ORIGINAL_QUESTS) // Load up the script & revert the stack. // This step's only here for cleanup purposes. err = lua_pcall(m_luaState, 0, LUA_MULTRET, 0); if (err != LUA_OK) { RetrieveLoadError(err, filename); return false; } #endif // Compiled! return true; }