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.

430 questions
4
votes
1 answer

LuaJIT lib built with /MD but does not cause runtime library mismatch with /MDd program?

I downloaded luajit source from http://luajit.org/git/luajit-2.0.git and built it with its msvcbuild.bat https://github.com/luvit/luajit-2.0/blob/master/src/msvcbuild.bat Judging from the batch file, it uses /MD to build the lua51.lib. When I…
Hsi-Hung Shih
  • 233
  • 1
  • 7
4
votes
3 answers

How can I create a pointer to existing data using the LuaJIT FFI?

I know there are examples of creating pointers using the LuaJIT FFI, but most of these aren't pointed to existing data. One such example of this is here: How to pass a pointer to LuaJIT ffi to be used as out argument? One thing that I haven't been…
4
votes
2 answers

Can't get LuaJIT to compile with cygwin

I am trying to install the latest version of LuaJIT on Windows. I followed the instructions for installing LuaJIT as best I could. I installed cygwin and the make packages, opened cygwin, cded to the unzipped source folder, and typed make. I get…
Houshalter
  • 2,508
  • 1
  • 18
  • 20
4
votes
1 answer

luajit segfault on garbage collection

I'm having an issue with a userdata defined with ffi.metatype. When the object if garbage collected, I get a segfault. Here is the code. ffi = require("ffi") srate = 48000 ffi.cdef[[ typedef struct sin_state { float _now; // time of last…
girodt
  • 369
  • 1
  • 10
4
votes
2 answers

LuaJIT equivalent of wlua.exe

In Windows, I want to know if there is an equivalent way of using LuaJIT like the standard Lua distribution wlua.exe, which is windowless. Or should I compile the modules and use them in a standard Lua interpreter? (not sure if this is possible).
Diogo
  • 115
  • 7
4
votes
1 answer

Lua (LuaJit) and object lifetime in C

I use LuaJit for extending a plain C application (using the Lua C API). The host application does manage memory for a lot of objects that I have written wrappers for in Lua. Now I would like to be able to delete objects from within the lua function,…
wirrbel
  • 3,173
  • 3
  • 26
  • 49
4
votes
2 answers

Lua: understanding table array part and hash part

In section 4, Tables, in The Implementation of Lua 5.0 there is and example: local t = {100, 200, 300, x = 9.3} So we have t[4] == nil. If I write t[0] = 0, this will go to hash part. If I write t[5] = 500 where it will go? Array part or hash…
happy_marmoset
  • 2,137
  • 3
  • 20
  • 25
4
votes
1 answer

Luajit: compiling bytecode into object format

The Luajit manual about the -b option says: The output file type is auto-detected from the extension of the output file name: c — C source file, exported bytecode data. h — C header file, static bytecode data. obj or o — Object file, exported…
Klaufir
  • 751
  • 1
  • 7
  • 10
3
votes
1 answer

luajit ffi constructor parameter routing

An example in the tutorial section : "Defining Metamethods for a C Type" looks as follows: local ffi = require("ffi") ffi.cdef[[ typedef struct { double x, y; } point_t; ]] local point local mt = { __add = function(a, b) return point(a.x+b.x,…
Hassan Syed
  • 20,075
  • 11
  • 87
  • 171
3
votes
2 answers

Reliable way of getting the exact decimals from any number

I'm having problem returning spesific amount of decimal numbers from this function, i would like it to get that info from "dec" argument, but i'm stuck with this right now. Edit: Made it work with the edited version bellow but isn't there a better…
Playhouse
  • 41
  • 4
3
votes
1 answer

Error while building a static Linux binary (with musl-libc) that includes LuaJIT

I've cloned the LuaJIT git repo and built it with: make STATIC_CC="musl-gcc" BUILDMODE="static" Then, I compiled a simple Lua "hello world" script into a C header file: luajit -b test.lua test.h test.h: #define luaJIT_BC_test_SIZE 52 static const…
Discussian
  • 492
  • 3
  • 10
3
votes
0 answers

Why does formatting a number round differently in LuaJIT vs. Lua?

Using string.format() (which supposedly defers to C's sprintf())) to format a number in LuaJIT rounds differently than every other Lua interpreter I've tried: $ lua -v Lua 5.4.1 Copyright (C) 1994-2020 Lua.org, PUC-Rio $ lua -e…
Caleb
  • 5,084
  • 1
  • 46
  • 65
3
votes
1 answer

How to configure mod_lua (apache) to use LuaJIT?

How do I configure mod_lua to use LuaJIT, instead of just plain Lua?
frooyo
  • 1,863
  • 3
  • 19
  • 21
3
votes
1 answer

LuaJIT FFI not loading symbols from executable

First Lua code: local ffi = require "ffi" ffi.cdef[[ void printc(const char *fmt, ...); ]] ffi.C.printc("Hello world") Does not work. Error: boot.lua:6: /usr/lib64/libluajit-5.1.so.2: undefined symbol: printc However, the symbol is in fact…
Accumulator
  • 873
  • 1
  • 13
  • 34
3
votes
2 answers

LuaJIT: How many times a script accessed global variables?

I'm trying to optimise my LuaJIT code, and I'm wondering, if there is a debug tool, or if I can write one, to check how many times my script accessed global variables/tables/functions?
user10894418