Questions tagged [luajit]

LuaJIT is a Just-In-Time Compiler for the Lua programming language. LuaJIT offers more performance, at the expense of portability. On the supported OS's (all popular operating systems based on x86 or x64 CPUs (Windows, Mac OSX, Linux, ...), ARM based embedded devices (Android, iOS) and PPC/e500v2 CPUs) it offers an API- and ABI-compatible drop-in replacement for the standard Lua interpreter.

Overview

LuaJIT is a high-performance, Just-In-Time(JIT) implementation by Mike Pall for the Lua programming language. It has been successfully used as a scripting middleware in games, 3D modelers, numerical simulations, trading platforms and many other specialty applications. It combines high flexibility with high performance and an unmatched low memory footprint: less than 125K for the virtual machine(VM) plus less than 85K for the JIT compiler (on x86).

LuaJIT has been in continuous development since 2005. It's widely considered to be one of the fastest dynamic language implementations. It has outperformed other dynamic languages on many cross-language benchmarks since its first release — often by a substantial margin. In 2009 other dynamic language VMs started to catch up with the performance of LuaJIT 1.x. Well, I couldn't let that slide. ;-)

2009 also marks the first release of the long-awaited LuaJIT 2.0. The whole VM has been rewritten from the ground up and relentlessly optimized for performance. It combines a high-speed interpreter, written in assembler, with a state-of-the-art JIT compiler. An innovative trace compiler is integrated with advanced, SSA-based optimizations and a highly tuned code generation backend. This allows a substantial reduction of the overhead associated with dynamic language features.

It's destined to break into the performance range traditionally reserved for offline, static language compilers.

Compatibility

LuaJIT implements the full set of language features defined by Lua 5.1. The virtual machine is API- and ABI-compatible to the standard Lua interpreter and can be deployed as a drop-in replacement.

LuaJIT offers more performance, at the expense of portability. It currently runs on all popular operating systems based on x86 or x64 CPUs (Linux, Windows, OSX etc.) or embedded systems based on ARM (Android, iOS) or PPC/e500v2 CPUs. Other platforms will be supported in the future, based on user demand and sponsoring.

388 questions
5
votes
3 answers

How to define C functions with LuaJIT?

This: local ffi = require "ffi" ffi.cdef[[ int return_one_two_four(){ return 124; } ]] local function print124() print(ffi.C.return_one_two_four()) end print124() Throws an error: Error: main.lua:10: cannot resolve symbol…
EpichinoM2
  • 137
  • 1
  • 10
5
votes
1 answer

Lua/Luajit: Indexing and named method at the same time?

The Lua PIL and Luajit FFI tutorial gave two usages of __index in the metatable. One is for indexing like obj[123], e.g., __index = function (self, k) return self._data+(k-self._lower) The other usage is to define named methods, as given in the…
Liang
  • 805
  • 1
  • 8
  • 11
5
votes
1 answer

Write-once table in lua?

I'd like to have a write-once table in Lua (specifically LuaJIT 2.0.3), so that: local tbl = write_once_tbl() tbl["a"] = 'foo' tbl["b"] = 'bar' tbl["a"] = 'baz' -- asserts false Ideally, this would otherwise function like a regular table (pairs()…
MikeMx7f
  • 897
  • 6
  • 12
5
votes
1 answer

What's the difference in the way Lua and LuaJIT process the code?

From what I understood, the standard Lua interpreter first compiles the input code to "bytecode" (the output of luac) and then "interpretes" that bytecode. But isn't that basically the definition of a JIT compiler? What does LuaJIT do then? How does…
user6245072
  • 1,841
  • 15
  • 30
5
votes
1 answer

What is "loadall.so"?

Looking at the default Lua cpath with luajit: luajit -e "print(package.cpath)" I get: ./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/luajit/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so What is the purpose of the loadall.so? It doesn't actually…
timbo
  • 9,491
  • 5
  • 45
  • 59
5
votes
1 answer

Can you Yield and Resume Luajit coroutines from anywhere in C?

I am trying to come up with a solution for yielding a Luajit coroutine from a C function that immediately creates a tasklet to be processed on another OS thread. According to various Lua documentations, and things began to heavily contradict each…
5
votes
2 answers

Can I make function `extern "c"`?

I have some cpp files, and I want to combine them with LuaJit using FFI. But the problem is that, I have to add extern "c" symbols for almost every function to make it possible for FFI to access them. Is there a simpler way to make this done?
Zehui Lin
  • 131
  • 6
5
votes
2 answers

Running luajit object file from C

From the documentation: http://luajit.org/running.html luajit -b test.lua test.obj # Generate object file # Link test.obj with your application and load it with require("test") But doesn't explain how to do these things. I guess…
Matthew
  • 9,723
  • 7
  • 34
  • 44
5
votes
1 answer

What should a lua iterator factory return in case of nothing to iterate

I am implementing a lua iterator and I wonder what the iterator factory (the function that creates the closure which is used to iterate over the iteratable, see list_iter on http://www.lua.org/pil/7.1.html ) should return in case of nothing to…
wirrbel
  • 2,859
  • 2
  • 19
  • 43
5
votes
1 answer

Scripting with LuaJIT and selectively sandboxing the FFI

After trying and witnessing the incredible ease with which I could integrate Lua and LuaJIT into my game engine, I'm convinced that that's the scripting language I want to use. I would like to use it for my AI, unit descriptions, map triggers, et…
Aktau
  • 1,717
  • 18
  • 28
5
votes
1 answer

Lua Table Memory?

This might be sort of a strange question, but curiosity got the best of me when I ended up getting a memory error after filling up a table with 14 million+ items. Is there a sort-of set memory limit for Lua tables, or is it somewhat dynamic at all?…
5
votes
2 answers

When using Luajit, is it better to use FFI or normal lua bindings?

I just started tinkering with Luajit with C++ and I see that it's FFI is really easy to use but I am not sure if it is the best solution for all (or at least most) cases. So is it better to use one or the other, or is it just preference?
benbot
  • 1,057
  • 9
  • 28
5
votes
4 answers

LuaJIT FFI callback performance

The LuaJIT FFI docs mention that calling from C back into Lua code is relatively slow and recommend avoiding it where possible: Do not use callbacks for performance-sensitive work: e.g. consider a numerical integration routine which takes a…
Miles
  • 28,169
  • 7
  • 57
  • 71
4
votes
1 answer

Converting a Lua file object to a C FILE*

I'm building a wrapper using LuaJIT and FFI. I have a C library with a function that takes a FILE* as a parameter. In a Lua function within which I open a file using io.open(). Is there a way to cast, convert, or extract from the Lua file object to…
johnzachary
  • 2,245
  • 2
  • 17
  • 9
4
votes
2 answers

Is it possible to use functions from c++ namespaces with luajit ffi?

I've got a lot of c++ code which contains a lot of functions and classes in namespaces (boost, for example). Now I'm trying to embed LuaJiT2 as script engine, but I cannot find anything about calling functions and using other stuff from…
1 2
3
25 26