A compiler that translates Venus files into Lua. Written in Lua.
The compiler reads a Venus file and replaces Venus syntax by Lua syntax.
It can also load and run the result.
The foreach statement will geneate a pairs statement.
localtable= {2,1,3,"test"}
foreachelintable {
print(el)
}will generate:
localtable= {2,1,3,"test"}
for_, elintabledoprint(el)
endFor comments -- and ## can be used
If something follows a -- it will always be treated as comment
fn can be used instead of function.
fntest() {
print("hi")
}will generate
functiontest()
print("hi")
endThe do,then and end statements can be replaced by curly braces syntax.
They can be used in functions, loops, conditions, etcetera.
For example:
do {
localtable= {2,1,3,"test","test2",3}
fnfindTest(t) {
repeat {
localfound=falselocalel=table.remove(t)
ifel=="test" {
found=true
} else {
print(el)
}
} untilfound
}
}will generate:
dolocaltable= {2,1,3,"test","test2",3}
functionfindTest(t) repeatlocalfound=falselocalel=table.remove(t)
ifel=="test" thenfound=trueelseprint(el)
enduntilfoundendendLambda syntax (args) => {...} can be used to create anonymous functions.
localresultfnstore_it(f) {
result=f(10,6)
}
store_it((a,b) => {
return (a-b) *2
})will generate:
localresultfunctionstore_it(f)
result=f(10,6)
endstore_it(function(a,b)
return (a-b) *2end)++ and -- can be used to add/sub by 1
locali=0localj=0i++j--will generate:
locali=0localj=0i=i+1j=j-1Assignment operators +=, -=, *=, /=, ^= and .= can be used for math on variables.
locala=0-- Increased bya+=2##Decreasedbya-=1##Multipliedbya*=8-- Divided bya/=2-- Powered bya^=3##Concatenatestringa .=" str"will generate
locala=0-- Increased bya=a+2-- Decreased bya=a-1-- Multiplied bya=a*8-- Divided bya=a/2-- Powered bya=a^3-- Concatenate stringa=a.." str"The init.lua returns a function for loading the compiler.
You have to call it with the path to the script itself as argument.
In case you have the LuaVenusCompiler directory within your project's
ways of loding it may be:
--in case your project is run within it's own folderlocalvc=dofile("LuaVenusCompiler/init.lua")("LuaVenusCompiler/")
--in case you have a variable called project_loc containing the path to your projects folderlocalvc=dofile(project_loc.."/LuaVenusCompiler/init.lua")(project_loc.."/LuaVenusCompiler/")
--using requirelocalvc=require("LuaVenusCompiler")("LuaVenusCompiler/")When it is loaded it can also be accessed with the global called "LuaVenusCompiler".
vc.dovenus(file) works like dofile(file)
It's argument can be a relative or absolute path to the file that should be run.
vc.loadvenus(file) works like loadfile(file)
It's argument can be a relative or absolute path to the file that should be loaded.
It returns a function that runs the generated lua.
vc.tl_venus_file(file) returns the lua generated from the files contents
It's argument can be a relative or absolute path to the file that should be translated.
It returns the generated lua as string.
vc.tl_venus_string(str) returns the lua generated from the given string
It returns the generated lua as string.
vc.convert_venus_file(venus_file_in,lua_file_out) generates a lua file
It's arguments can be relative or absolute paths.
The venus_file_in will be converted to lua and written to lua_file_out.