Skip to content

Instantly share code, notes, and snippets.

@TheLinx
Created May 15, 2010 22:24
Show Gist options
  • Save TheLinx/402454 to your computer and use it in GitHub Desktop.
Save TheLinx/402454 to your computer and use it in GitHub Desktop.
Braindamage

What is this I dont even

Braindamage is a NEW scripting language that makes Brainfuck even more Brainfuckier!

bd

bd runs Braindamage scripts.

bdc

bdc converts Brainfuck scripts to the clearly superior alternative.

What do I need to make this work?

For now, you need to run Lua on a UNIX-like operating system.

#!/usr/bin/env lua
if not arg[1] then
print("No input file specified!")
os.exit(1)
end
local tableInsert,tableConcat,ioOpen,osExecute,osRemove = table.insert,table.concat,io.open,os.execute,os.remove
local fhand,ferr = ioOpen(arg[1], "r")
if not fhand then
print(ferr)
os.exit(1)
end
fcont = fhand:read("*all")
fhand:close()
local i = 0
local out = {}
for n=1,#fcont do
local part = fcont:sub(n,n)
if part == " " then
i = i + 1
elseif part == "\n" then
tableInsert(out, string.char(i))
i = 0
else
print("Malformed Braindamage script!")
end
end
local fhand = ioOpen("/tmp/bdtmp", "w")
fhand:write(tableConcat(out))
fhand:close()
osExecute("bf /tmp/bdtmp")
osRemove("/tmp/bdtmp")
#!/usr/bin/env lua
if not arg[1] then
print("No input file specified!")
os.exit(1)
end
if not arg[2] then
print("No output file specified!")
os.exit(1)
end
local tableInsert,tableConcat,ioOpen,stringByte,stringRep = table.insert,table.concat,io.open,string.byte,string.rep
local fhand,ferr = ioOpen(arg[1], "r")
if not fhand then
print(ferr)
os.exit(1)
end
fcont = fhand:read("*all")
fhand:close()
local i = 0
local out = {}
for n=1,#fcont do
tableInsert(out, stringRep(" ",stringByte(fcont:sub(n,n))).."\n")
end
local fhand,ferr = ioOpen(arg[2], "w")
if not fhand then
print(ferr)
os.exit(1)
end
fcont = fhand:write(tableConcat(out))
fhand:close()
@TheLinx
Copy link
Author

TheLinx commented May 15, 2010

I am aware how ugly it's programmed at the moment, but I whipped it up in 10 minutes.

I'm lazy.

@sirupsen
Copy link

Awesome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment