Don't click here unless you want to be banned.

LSL Wiki : Stack

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are ia360925.us.archive.org

stack

Stack memory is a LIFO-based memory structure.

Stack is used when passing variables into functions. The data is "pushed" onto the stack, then "pulled" off the stack by a function. Each script has it's own stack space which counts towards a script's memory allocation. (This is why it is common to see a script crash when passing complete lists between functions, as it effectively doubles its size temporarily--while passing the information to functions.)

When calling a new function, the stack operates as follows:

Push: Variable A onto stack (make a copy)
Push: Variable B onto stack
Push: Variable C onto stack
Store location
Adjust memory offset
Jump to the function
<do function stuff>
Push: Result
Jump back to stored location
Re-adjust memory offset
Pull or Peak: Result as needed.

The above example is basicly how LSL does it, but not exactly. --BW


memory | FIFO
Comments [Hide comments/form]
Here are some functions to simulate a stack operation using lists:
list stack = [];

stackInit()
{
    stack = [];
}

stackPush(list data)
{
    stack = (stack = []) + data + stack;
}

list stackPop()
{
    list data = llList2List(stack, 0, 0);
    stack = (stack = []) + llDeleteSubList(stack, 0, 0);
    return data;
}

list stackPeek()
{
    return llList2List(stack, 0, 0);
}

integer stackLength()
{
    return llGetListLength(stack);
}
-- AsiraSakai (2006-11-23 18:38:41)
Attach a comment to this page: