
Embedding LuaJIT in 30 minutes - fcambus
http://en.blog.nic.cz/2015/08/12/embedding-luajit-in-30-minutes-or-so/
======
fosk
LuaJIT is such an amazing just-in-time compiler, faster than the traditional
Lua compiler, supported on many platforms and used everywhere where speed and
performance are a priority.

For example it's being used in Redis to provide Lua scripting, and can also be
used with nginx (OpenResty). While developing Kong
([https://github.com/Mashape/kong](https://github.com/Mashape/kong)) we
noticed that LuaJIT provided substantial performance improvements.

I hope that the recent step down of the main committer won't affect the future
of the project [1].

[1] [http://www.freelists.org/post/luajit/Looking-for-new-
LuaJIT-...](http://www.freelists.org/post/luajit/Looking-for-new-LuaJIT-
maintainers)

~~~
asymmetric
Kong looks like a really interesting project!

Just curious as to why you chose Lua, and what your experience with it was.

~~~
fosk
We decided to use Lua because we are leveraging OpenResty [1]. It took a while
to setup the development environment, since there aren't many big, public,
projects based on OpenResty + Lua, but we are on a good track now.

Lua is a very simple language, no batteries included, that's easy to learn and
actually quite fun to write. It also has a package manager called Luarocks [2]
(that Kong is sponsoring too). The ecosystem is still relatively young, but
it's growing - and that's also thanks to tools like LuaJIT.

[1] [http://openresty.org/](http://openresty.org/)

[2] [https://luarocks.org/](https://luarocks.org/)

------
vvanders
Lua is such a fantastic language for embedding.

I've seen entire game logic done in 200kb on platforms that had less than 32mb
of total CPU memory.

------
aDevilInMe
The author informs that the stack is "difficult bit to wrap your head around
first", then makes a bizarre statement "Once again – pushed values are indexed
with negative, function arguments with positive numbers." This is not correct,
you can use positive or negative indexes in either case. Positive indexes are
absolute and negative are relative to the top of the stack.

~~~
vavrusa
Yes you're right, I just hoped that this may be a useful mnemonic (admittedly
maybe a confusing one, but worked for me) for people starting with Lua. A
simplification. How the index with negative offset is computed is explained in
detail in the linked PIL/"The Stack" then. From my experience, the most common
errors for beginners are 1-based indexing and stack manipulation.

