https://github.com/d5/tengo2lua
Experimental Tengo to Lua transpiler
https://github.com/d5/tengo2lua
lua tengo transpiler
Last synced: 6 months ago
JSON representation
Experimental Tengo to Lua transpiler
- Host: GitHub
- URL: https://github.com/d5/tengo2lua
- Owner: d5
- License: mit
- Created: 2019-03-14T16:47:24.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-14T17:16:12.000Z (almost 7 years ago)
- Last Synced: 2025-04-11T07:04:09.235Z (10 months ago)
- Topics: lua, tengo, transpiler
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 9
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Tengo2Lua
An experimental transpiler to convert [Tengo](https://github.com/d5/tengo) source code into Lua code.
### Limitations
- Tengo module system is not implemented.
- Tengo `int` and `float` values are both converted into `Number` values in Lua.
- Array slicing is not implemented (`[1,2,3,4,5][1:3]`). _But string slicing is implemented._
- Character literal is not supported.
- String indexing is not supported.
- Bitwise operators is not implemented.
- Different boolean truthiness
- Different type coercion logic
### Example
Tengo code:
```golang
each := func(x, f) { for k, v in x { f(k, v) } }
sum := 0
each([1, 2, 3], func(i, v) { sum += v })
```
is converted into:
```lua
function __iter__(v)
if v.__a then
local idx = 0
return function()
if v[idx] == nil then
return nil
end
idx = idx + 1
return idx-1, v[idx-1]
end
else
return pairs(v)
end
end
getmetatable("").__add=function(a,b) return a..b end
local each=function(x,f)
for k, v in __iter__(x) do
local __cont_1__ = false
repeat
f(k,v)
__cont_1__ = true
until 1
if not __cont_1__ then break end
end
end
local sum=0
each({[0]=(1),(2),(3), __a=true},function(i,v)
sum=sum+v
end
)
```