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
6
votes
1 answer

How can I list modules and check functions exist at the command line?

Like many "(windows) users" I do not want to spend time learning to compile anything from source. So Lua seems a very good choice for a hobbyist. Sorry if this is a very simple problem - but... Q1. How can I list the modules available to any given…
Gavin
  • 477
  • 5
  • 16
6
votes
1 answer

How to pass a pointer to LuaJIT ffi to be used as out argument?

Assuming there is following C code: struct Foo { int dummy; } int tryToAllocateFoo(Foo ** dest); ...How to do following in LuaJIT? Foo * pFoo = NULL; tryToAllocateFoo(&pFoo);
Alexander Gladysh
  • 39,865
  • 32
  • 103
  • 160
6
votes
1 answer

luajit2.0.0 -- Segmentation fault: 11

I use a simple example from http://lua-users.org/wiki/SimpleLuaApiExample to make a test. The sample can be statically linked with libluajit.a with a success, but this error message occurs when you run it: Segmentation fault: 11 I use LuaJIT-2.0.0…
douyw
  • 4,034
  • 1
  • 30
  • 28
5
votes
3 answers

Would my DSL for Lua work...? (this seems too simply to be true)

I really love Lua as a programming language BUT, it bugs me unbelievably to have to constantly type "local" for all my local variables. It just makes my code look more cluttered. So I am wondering, can I create a Domain Specific Language (DSL) on…
nickb
  • 9,140
  • 11
  • 39
  • 48
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
  • 2
  • 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
  • 1,015
  • 1
  • 10
  • 13
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
  • 927
  • 6
  • 13
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
3 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
  • 186
  • 9
5
votes
2 answers

How do I convert a lua string to a C char*?

I've used the luajit ffi library to wrap a C library that contains a function to draw text on a ppm file: void drawText(frameBuffer *fb, int px, int py, char* text, pixel color) When I try to call it from lua using a string I get this error bad…
BarFooBar
  • 1,086
  • 2
  • 13
  • 32
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
  • 11,203
  • 9
  • 38
  • 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
  • 3,173
  • 3
  • 26
  • 49
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,847
  • 21
  • 30
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?…
Stephen Leitnick
  • 120
  • 1
  • 10
5
votes
2 answers

How do I convert a cdata structure into a lua string?

I'm in the middle of writing a small application that needs to read some complex binary messages in LuaJit. I've been using the bit module and string.rep a lot. However, it's all very cumbersome. I'm new to using LuaJit and think there might be a…
hookenz
  • 36,432
  • 45
  • 177
  • 286
1 2
3
28 29