fix: makes more concise by removing one-used var

This commit is contained in:
bangonicdd
2025-04-09 18:09:02 +09:00
parent dc753adf1f
commit 2d50935079

View File

@@ -23,7 +23,6 @@ interface LuaEngineState {
code?: string; code?: string;
engine?: LuaEngine; engine?: LuaEngine;
mutex: Mutex; mutex: Mutex;
wasEmpty?: boolean;
chat?: Chat; chat?: Chat;
setVar?: (key:string, value:string) => void, setVar?: (key:string, value:string) => void,
getVar?: (key:string) => string, getVar?: (key:string) => string,
@@ -59,11 +58,8 @@ export async function runLua(code:string, arg:{
luaEngineState.setVar = setVar luaEngineState.setVar = setVar
luaEngineState.getVar = getVar luaEngineState.getVar = getVar
if (code !== luaEngineState.code) { if (code !== luaEngineState.code) {
if (!luaEngineState.wasEmpty){ luaEngineState.engine?.global.close()
luaEngineState.engine.global.close()
}
luaEngineState.code = code luaEngineState.code = code
luaEngineState.wasEmpty = false
luaEngineState.engine = await luaFactory.createEngine({injectObjects: true}) luaEngineState.engine = await luaFactory.createEngine({injectObjects: true})
const luaEngine = luaEngineState.engine const luaEngine = luaEngineState.engine
luaEngine.global.set('setChatVar', (id:string,key:string, value:string) => { luaEngine.global.set('setChatVar', (id:string,key:string, value:string) => {
@@ -605,7 +601,6 @@ async function getOrCreateEngineState(
const creationPromise = (async () => { const creationPromise = (async () => {
const engineState: LuaEngineState = { const engineState: LuaEngineState = {
mutex: new Mutex(), mutex: new Mutex(),
wasEmpty: true,
}; };
LuaEngines.set(mode, engineState); LuaEngines.set(mode, engineState);