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
0
votes
0 answers

Loop in torch seems much slower than it should be

I've the following piece of code for i=1,A do for j=1,B do self.gradInput:narrow(1, self.C[i][j], 1):add(gradOutput[2][i][j]) end end in a custom module in torch. For values of A = 18K, B=30, this loop is taking ~4 s (measured using…
Opt
  • 4,774
  • 3
  • 28
  • 28
0
votes
1 answer

Luajit segfault on module loading

I currently have a problem where Lua5.1/Lua5.2 can load & use a module, but LuaJIT can't. This is strange, since LuaJIT should be ABI-compatible to Lua, right? How could I fix this? The module: https://github.com/gabrield/v4l-lua
max1220
  • 44
  • 5
0
votes
1 answer

Love 2D and ffi luajit, trying to use the PHYSFS_enumerateFiles()

It always return a String which is (at least I guess) the table identifier someone can help in anyway? Thats my function: function listFiles(dir) local ffi = require("ffi") ffi.cdef[[char ** PHYSFS_enumerateFiles ( const char * dir …
0
votes
1 answer

luajit copy table is slow

Within a larger lua-script, I have to copy several tables dt: for i=1,dt:nrow() do local r = {} for j=1,dt:ncol() do r[j] = dt[i][j] end rslt:append(r) end The tables are about 50,000 lines x 25 cols, containing mainly…
0
votes
1 answer

How I get the cdata out in c function with variable arguments using luajit?

Here is the code. The aim is to print messages. In PrintC, I would like to get e...but arrives as cdata. How can I unpack that or circumvent that? extern "C" { static int PrintC ( lua_State *L ) { // does not work cdata …
Aftershock
  • 5,205
  • 4
  • 51
  • 64
0
votes
0 answers

Pattern that matches UTF-8 encoded characters

Given a byte sequence that is valid UTF-8, I would like to iterate over each of the encoded characters. In my working environment (LuaTeX), only Lua 5.2 and LuaJIT 2.0.3 are available, so I cannot use any of the facilities provided by the UTF-8…
djsp
  • 2,174
  • 2
  • 19
  • 40
0
votes
0 answers

Expected from ffi.cast in LuaJIT

I am trying to write a LuaJIT FFI module for sqlite3. The exec function takes a callback for each row returned. https://www.sqlite.org/c3ref/exec.html in LuaJIT I simply enter ffi = require 'ffi' ffi.cast("int…
user2240431
  • 338
  • 2
  • 12
0
votes
1 answer

Is corona sdk compatible with luaJit?

Started looking into lua and corona sdk and couldn't find any info on this topic.
daniel
  • 1,205
  • 1
  • 10
  • 15
0
votes
1 answer

LuaJIT: pass pointer to existing 2D array of doubles from C to script?

I want to manipulate existing 2D arrays of doubles directly in LuaJIT by passing a pointer to the script. I see it isn't possible to create pointers to existing data. Can I pass a pointer to an existing array of primitives from C to LuaJIT and…
PaulR
  • 706
  • 9
  • 27
0
votes
1 answer

Can lua source files be obfuscated/encrypted while using it with Nginx HttpLuaModule? If yes then how?

I am using Lua to create a custom authentication layer for my backend services. Nginx is compiled with Lua module and LuaJIT. It works fine. I would like to do some encryption of tokens that I am serving back in those lua files and want that no one…
dev0z
  • 2,275
  • 1
  • 15
  • 16
0
votes
1 answer

How to print a fixed array of char in LuaJIT?

I'm trying to print the contents of a null terminated string that is stored in a fixed array. The array is memset'd to zero at the start and then is populated with a null terminated string. I'm attempting to print the string. This…
101010
  • 14,866
  • 30
  • 95
  • 172
0
votes
2 answers

How to merge clib functions into a table using LuaJIT and FFI?

I have a table/object defined in Lua. I'm trying to add some methods from a C-API dll. I could attach the methods one at a time, but there are a lot of them. The last line of the code below is how I would like to do it. It is supposed to merge…
101010
  • 14,866
  • 30
  • 95
  • 172
0
votes
0 answers

C++ and Lua5.1-2 / LuaJIT

So I'm working on embedding Lua5.1-2 using LuaJIT in a C++ application and included the ability for lua scripts to "subscribe" to events raised in the C++ code and successfully stored the function reference using luaL_ref and successfully called the…
Chipper
  • 1
  • 1
0
votes
1 answer

LuaJit - Get metatable from module/package and assign it to userdata

Say I have this metatable for a custom struct vector2_t which is inside a module mymod like this: local mymod = {} local ffi = require("ffi") local C = ffi.C ffi.cdef[[ typedef struct { double x; double y; }…
SLC
  • 2,167
  • 2
  • 28
  • 46
0
votes
1 answer

Pointers and Reference issue in LuaJIT FFI

I have this function (written in C++ here): GameSession *theSession = NULL; ... ... startSesion(&theSession) I have managed to get this running properly using the LuaJIT FFI here: local session = ffi.new("GameSession*[1]",…
theman
  • 345
  • 1
  • 14