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

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,435
  • 2
  • 19
  • 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…
4
votes
3 answers

How do I use lua keyword as a table key?

Problem When I use do, a lua keyword as a table's key it gives following error > table.newKey = { do = 'test' } stdin:1: unexpected symbol near 'do' > I need to use do as key. What should I do ?
MrAdityaAlok
  • 95
  • 1
  • 6
4
votes
3 answers

LuaJIT FFI load dll error

I want to code some functions in C to use in Lua and the easiest way to do this I think I can find is using LuaJIT's FFI. I have a C file "add.c": int add(int a, int b){ return a+b; } I assemble it into "add.o" with: gcc -c add.c I make…
CircArgs
  • 570
  • 6
  • 16
4
votes
1 answer

Openresty Hello world with docker

I'm trying make my application dockerize for that I've been following official openresty dockerfile. Os in my system is Ubuntu 16.04 64 bit. I have already pull that image using this cmd. docker pull openresty/openresty:1.11.2.3-xenial Now I want…
Rahul
  • 1,013
  • 1
  • 10
  • 24
4
votes
1 answer

Build static binary with cgo, LuaJIT and musl

After reading Statically compiled Go programs, always, even with cgo, using musl I'm trying to use described method to statically link LuaJIT. Using https://github.com/aarzilli/golua go bindings Assuming musl and golua are already installed Go…
Michael
  • 481
  • 2
  • 6
  • 13
4
votes
1 answer

Returning a string table array from C to LuaJIT via FFI

I would like to have a C function return a string table array (e.g. {"a", "b", "c"}) to a Lua script via LuaJIT. Which is the best way to do it? I thought of returning a single concatenated string with some separator (e.g. "a|b|c") then splitting it…
Enrico Detoma
  • 3,159
  • 3
  • 37
  • 53
4
votes
1 answer

Is there an option to make LuaJIT do bounds checking?

LuaJIT knows the C types it defines, and the lengths of the arrays, but it doesn't check the bounds: ffi = require("ffi") ten_ints = ffi.typeof("int [10]") p1 = ten_ints() print(ffi.sizeof(p1)) -- 40 var_ints = ffi.typeof("int [?]") p2 =…
MWB
  • 11,740
  • 6
  • 46
  • 91
4
votes
1 answer

How to change working directory in Torch REPL

Title says it all, how can one change the working directory inside the Torch REPL? I tried using calls to os.execute('cd some_dir') but this doesn't work, as demonstrated here. th> pwd() --prints: /home/user/Code th> os.execute('cd ..') --prints:…
sudo-nim
  • 408
  • 3
  • 14
4
votes
1 answer

Requiring a LuaJIT module in a subdir is overwriting a module of the same name in the parent dir

I have a file setup like this: main.lua (requires 'mydir.b' and then 'b') b.lua mydir/ b.so (LuaJIT C module) From main, I do this: function print_loaded() for k, v in pairs(package.loaded) do print(k, v) end end print_loaded() require…
Tyler
  • 28,498
  • 11
  • 90
  • 106
4
votes
1 answer

Why doesn't LuaJIT's FFI module require declared calling conventions?

This is something I've been curious about for a while: I was wondering how LuaJIT's FFI module manages to use the correct calling conventions for invoking external native functions without any need for declarations in the user's prototypes. I tried…
Charles Grunwald
  • 1,441
  • 18
  • 22
4
votes
2 answers

How to set the environment variable of zerobrane studio

I install all torch package into my local file torch-distro(Followed by this tutorial). I want to use Zerobrane to debug my code. Zerobrane can't find my local path of torch. How Can I set my local path to the Zerobrane environment variable. I tried…
Samuel
  • 5,977
  • 14
  • 55
  • 77
4
votes
1 answer

How to integrate LuaJIT with LuaRocks on Windows?

I downloaded the source of LuaJIT and compiled it with msvc120.dll (VS 2013 x64). When I run it from the command line I have no problems executing some basic lua. Now the LuaJIT installation guide mentions moving luajit.exe and lua51.dll into their…
Akkuma
  • 2,215
  • 3
  • 16
  • 21
4
votes
1 answer

ffi.C missing all declarations for all symbols

I see in the documentation ffi.C.free is something I can use to free up malloc. I am attempting to do so here: callbacks.free_buffer = function(buffer) print("free_buffer_callback") ffi.C.free(buffer) end I get this error: missing declaration…
theman
  • 345
  • 1
  • 14
4
votes
1 answer

LuaJit FFI Return string from C function to Lua?

Say I have this C function: __declspec(dllexport) const char* GetStr() { static char buff[32] // Fill the buffer with some string here return buff; } And this simple Lua module: local mymodule = {} local ffi =…
SLC
  • 2,167
  • 2
  • 28
  • 46