How can i implement a stack in a script?

Posted by Smokin711 on Wed 26 Apr 2006 02:58 PM — 2 posts, 11,982 views.

#0
I am trying to figure out how to implement stack functionality...push and pop...to use in my scripts.

It seems that mushclient uses vbscript 5.6 and i'm not really familiar with it...

also, if I want to define a class for use with my scripts, can that be done? or is this sounding more like a plugin?
Australia Forum Administrator #1
Do you particularly want to use VBscript? These days we are recommending Lua as the preferred scripting language.

In any case, any language can be used to implement a stack. Basically you want:

  • An array in which you store the things you want to stack
  • A counter which indicates how many things are in the array


To push something you add it to the array at the "stack top" position, and add 1 to that counter.

To pop something you remove it from the "stack top" position, and subtract 1 from that counter.

In VBscript variables are variants, which means elements can be of any type. The same applies to Lua, where a table can consist of elements of any type, including other tables.




I'm not sure what you mean by "define a class". You don't necessarily have to use plugins, the main advantage of them is that they are modular, but do not offer particular advantages over normal scripting, excepting the plugin callback routines, which MUSHclient looks for.