rStack - A stack implementation in Roblox

Hey! If you don’t know what a stack-based language is, you can read about it here. If you do know, great! This isn’t a language, but more like a library. I made it in like 15 minutes, but I thought it was cool so I open sourced it. Here are some code examples.

Examples

This code will print 350 by adding 100 and 250 to the stack, then adding them.

local rStack = require(script.Parent.rStack).new()

rStack:append(100)
rStack:append(250)
rStack:add() --350
rStack:print() --Prints 350

Or you can chain it infinitely.

local rStack = require(script.Parent.rStack).new()

rStack:append(100)
rStack:append(250)
rStack:add() --350
rStack:append(10)
rStack:mul() --3500
rStack:append(3500)
rStack:sub() --0
rStack:print() --Prints 0

If statement

rStack:append(1)
rStack:append(1)
rStack:eq()
rStack:ifstmt(function()
	print("math works")
end)

While statement

rStack:append(1)
rStack:append(1)
rStack:eq()
rStack:whilestmt(function()
	print("built in task.wait")
end)

It serves no actual purpose, but the concept of stack-based languages are cool. Feel free to give any feedback.

You can download it here: rStack.rbxm
Gist: A stack implementation in Roblox

2 Likes

Could you upload the source to a Gist?

Sure, it’s on the original post. I’m actually making a stack-based high-level interpreted language in Python (might rewrite it in JavaScript).

Decided to update this because why not.

Added:
- Comparisions
- If statements
- While statements

See Examples for the new additions.