Skip to content

loops do not work #141

@Drago-Cuven

Description

@Drago-Cuven

any while loop or for loop seems to strangely enough completely stop JS and freeze the page until done. no errors are reported and i can't find a way around it.

for example:

local count = 1

while count <= 100 do
    print(count)
    count = count + 1
end

print("Loop finished.")

will technically work, but during the time its taking to print it all, it will completely freeze the page, any interactions with the page will go unnoticed, then when complete, everything previously done will just "catch up" all at once. i don't know how to fix this, or get around it.

here is the snippet of code that lua is run from:

async runLua({ CODE }, util) {
    if (!canRunLUA) return '';

    // Initialize Lua commands only once
    if (initWCSCMDS) {
        this.initLuaCommands(util);
        initWCSCMDS = false;
    }

    let result;
    try {

        result = await lua.doString(Cast.toString(CODE));
    } catch (err) {
        console.error(err);
        const msg   = err instanceof Error ? err.message : Cast.toString(err);
        const match = msg.match(/\[string.*?\]:(\d+)/);
        const line  = match ? parseInt(match[1], 10) : -1;
        let linemsg = '';

        if (line > 0) {
            const lines = CODE.split(/\r?\n/);
            linemsg = lines[line - 1] || '';
        }

        luaError.cur  = { msg, line, linemsg };
        luaError.last = { ...luaError.cur };

        // Clean the stack after error
        while (lua.global.getTop() > 0) lua.global.pop();

        util.startHats('DragoLua_onError');
        return '';
    }
    // Clean the stack after execution
    while (lua.global.getTop() > 0) lua.global.pop();

    // Check for invalid returns (functions instead of values)
    if (typeof result === 'function') {
        const msg = `Invalid return: received a function value instead of a result → ${Cast.toString(result)}`;
        luaError.cur  = { msg, line: -1, linemsg: '' };
        luaError.last = { ...luaError.cur };
        util.startHats('DragoLua_onError');
        return '';
    }

    // Reset current error state
    luaError.cur = { msg: '', line: 0, linemsg: '' };

    return result ?? '';

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions