7 ms·
Terra: A low-level counterpart to Lua
- laarc 11y agoTerra seemed promising when I ran across it a month ago. Does anyone know if it's possible to use LuaJIT's ffi module while writing Terra code? What I mean is, there is a large body of existing code that I'd like to run alongside Terra. But if the choice is Terra xor LuaJIT, this becomes difficult.
- an_ko 11y agoYou might be looking for http://terralang.org/api.html http://terralang.org/api.html § Managing Terra Values from Lua. Quoting: > We provide wrappers around LuaJIT’s FFI API that allow you to allocate and manipulate Terra objects directly from Lua.
- corysama 11y agoYou can use Lua, Terra or both at runtime. The Lua part is LuaJIT including the ffi. The Terra part is LLVM and can link directly to C (maybe C++?). Lua can be used as a metaprogramming system to produce a static Terra .o or exe. Or Lua can be used as a runtime that can JIT and invoke Terra functions on the fly.
- andrewmcwatters 11y agoSo this is LuaJIT's ffi with some bastardized syntax that immediately becomes incompatible with any other Lua syntax parser, because "pretty." Just no.
- mpdehaan2 11y agoIt's been a long time since I've done Lua (2005/2006 IIRC?), but I remember Lua's C embedding API being remarkably excellent already. C calling Lua, calling back into C, back and forth across the boundary was absolutely painless. Compared with experiencing that in many other languages, at the time, I was convinced that was as easy as it is. (Plus, the size of the lua runtime made it great for embedded projects, whereas now embedded computing has gotten so much more powerful you can really include almost any language stack if you really want to) As a result, I'm not positive why I need a C-like layer on top for cases where I probably want to write C.
- andrewmcwatters 11y agoExactly. Anyone who has ever actually done embedded work with Lua knows you can hardly get any closer in terms of "low-level" outside of the C API besides using LuaJIT's ffi. If anything this is actually a high level abstraction on top of LuaJIT's ffi, so this is far from low level. God forbid anyone criticize anything on HN.
- haberman 11y agoI think Terra functions are AOT compiled and have explicit strong types. So it's quite a different thing that LuaJIT. For example, you could use Terra to actually write a JIT.
- andrewmcwatters 11y agoWhy would you use Terra to write a JIT? It uses LLVM. To write JIT in JIT?
- vbit 11y agoThe front page describes three distinct use cases for Terra. While criticism is welcome, it certainly appears that you are missing the uses for Terra. Consider the third case - you can write Terra functions (cleaner syntax than C) and use Lua as a meta-programming language that produce more Terra functions (vastly superior to C macros) which then compile down via LLVM to machine code. Your final code has no Lua pieces.
- mpdehaan2 11y agoIt's been a long time since I've done Lua (2005/2006 IIRC?), but I remember Lua's C embedding API being remarkably excellent already. C calling Lua, calling back into C, back and forth across the boundary was absolutely painless. Compared with experiencing that in many other languages, at the time, I was convinced that was as easy as it is. (Plus, the size of the lua runtime made it great for embedded projects, whereas now embedded computing has gotten so much more powerful you can really include almost any language stack if you really want to) As a result, I'm not positive why I need a C-like layer on top for cases where I probably want to write C.
- an_ko 11y agoAs an experiment, I've tried replacing C with Terra for a few projects. It feels like C++, except without the constant guilt. Having a proper hygienic macro system (instead of C's very limited string-replacement "macros" or C++ template hell) is a really helpful abstraction, and the compile-time stuff you can do can basically act as a build system. So I got excited and planned to use it to make a game, but although it can import existing C libraries [1], it can't import global variables, constants, or macros that take arguments, which puts a whole lot of existing libraries just out of reach. This doesn't seem to have stopped Leonard Ritter from using it for Nowhere anyway, though being a crazy genius, he seems to have written his whole environment from scratch. [2] [3] [1]: http://terralang.org/api.html#c-backwards-compatibility http://terralang.org/api.html#c-backwards-compatibility [2]: http://blog.duangle.com/2015/01/conspire-programming-environment-for.html http://blog.duangle.com/2015/01/conspire-programming-environ... [3]: https://bitbucket.org/duangle/nonelang/src https://bitbucket.org/duangle/nonelang/src
- nickpsecurity 11y ago"Having a proper hygienic macro system (instead of C's very limited string-replacement "macros" or C++ template hell) is a really helpful abstraction, and the compile-time stuff you can do can basically act as a build system." Exactly. I long ago came to the conclusion that any modern systems language should have a hygienic, macro system to balance productivity/maintenance against performance. Just makes things so much easier. That morons can abuse it is no reason not to have it in the language as they abuse everything haha.
- shahbazac 11y agoHow is terra's performance? You sort of compared it to C++, can it actually be compared with C++ in terms of latency performance?
- an_ko 11y agoVery good. I didn't benchmark it myself, but the language is designed for high-performance computing, and the authors' PLDI paper [1] shows it is competitive. Given that at the lowest levels, Terra basically reimplements C, and both compile to LLVM IR, similar performance is unsurprising to me. The main point that gives Terra an edge is that its macro system makes implementing and testing potential optimisations easier. [1]: http://terralang.org/pldi071-devito.pdf http://terralang.org/pldi071-devito.pdf § 6. Evaluation
- haberman 11y agoPrevious discussion: https://news.ycombinator.com/item?id=5702793 https://news.ycombinator.com/item?id=5702793
- rch 11y agoHave a quick look at the 'past' link below the article title. It's a handy new feature.
- nickpsecurity 11y agoDidn't know it was there. Thanks for the tip!
- haberman 11y agoInteresting, but I don't think it's useful because it doesn't actually tell you if previous discussion exists or not until you actually click it. I'm not going to click "past" on every story for the 1% chance that it will actually have results. For it to be useful (to me at least), it should only show up if previous discussion exists, and it should be more prominent.
- mturmon 11y agoInsightful comment. I thought the "past" link was cool when it was pointed out to me. Sometimes past discussions are superior to the current one. But in practice, I almost never use "past", except when I'm pretty sure I have seen the piece before. Your suggestion might fix the issue.
- nickpsecurity 11y agoSite is down right now. Here's Wayback Machine: https://web.archive.org/web/20150424222319/http://terralang.org/ https://web.archive.org/web/20150424222319/http://terralang....
- badwolf93 11y agothere's nothing wrong with Lua
- Sleaker 11y agoThis looks very cool, my only concern is that luajit is lagging behind LUA and is in need of a new maintainer, how bound to luajit is terra for JIT compilation features? Is it something the terra developers are going to help with?