This is a simple Brainfuck interpreter implemented in Lua. It supports all Brainfuck commands, including input and output operations.
- Supports all Brainfuck commands (
>,<,+,-,[,],,,.) - Allows execution of Brainfuck programs
Clone this repository or download the Brainfuck.lua file and require it in your Lua script.
local Brainfuck = require("Brainfuck")Create a new Brainfuck interpreter instance and run a program:
local Brainfuck = require("Brainfuck")
local myBrainfuck = Brainfuck.new()
myBrainfuck:Run(
[[++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.]]
)The following program prints Hello World!:
myBrainfuck:Run(
[[
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
]]
)To reset the Brainfuck interpreter:
myBrainfuck:Clear()| Command | Description |
|---|---|
> |
Move data pointer to the right |
< |
Move data pointer to the left |
+ |
Increment the value at the data pointer |
- |
Decrement the value at the data pointer |
. |
Output the character at the data pointer |
, |
Read a character from input and store it at the data pointer |
[ |
Jump past matching ] if value at data pointer is zero |
] |
Jump back to matching [ if value at data pointer is nonzero |
This project is licensed under the MIT License.