Skip to content

Repository files navigation

LuaVenusCompiler

luacheck
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.

Features:

"foreach" loop

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)
end

Comments

For comments -- and ## can be used If something follows a -- it will always be treated as comment

Functions

fn can be used instead of function.

fntest() {
print("hi")
}

will generate

functiontest()
print("hi")
end

Curly braces based syntax

The 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)
enduntilfoundendend

Lambdas / Anonymous functions

Lambda 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)

Increment and Decrement

++ and -- can be used to add/sub by 1

locali=0localj=0i++j--

will generate:

locali=0localj=0i=i+1j=j-1

assignments

Assignment 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"

Working with the compiler

Loading

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".

Running Venus files

vc.dovenus(file) works like dofile(file)
It's argument can be a relative or absolute path to the file that should be run.

Loading Venus files

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.

Generating Lua code

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.

Generating Lua files

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.

About

a compiler that loads and runs lua Venus scripts

Topics

Resources

Stars

13 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages