Version 0 of LuaJIT

Updated 2017-06-03 06:23:29 by dbohdan

LuaJIT is a remarkably fast JIT compiler that is source- and binary extension-compatible with Lua 5.1.

Creating a Tcl interpreter in LuaJIT

dbohdan 2016-09-17: LuaJIT comes stock with a really nice FFI library . The code below is a translation of PYK's example from the Ffidl page that shows how to create a Tcl interpreter in LuaJIT.

#! /usr/bin/env luajit

ffi = require("ffi")
-- The following line is for openSUSE Tumbleweed. If you run a different OS
-- you should probably replace it with something like
-- local tcl = ffi.load("tcl8.6")
local tcl = ffi.load("/usr/lib64/")
typedef struct Tcl_Interp Tcl_Interp;
typedef struct Tcl_Obj Tcl_Obj;
typedef struct Tcl_DString {
    char *string;
    int length;
    int spaceAvl;
    char staticSpace[200];
} Tcl_DString;

Tcl_Obj *        Tcl_NewStringObj(const char *bytes, int length);
Tcl_Interp *     Tcl_CreateInterp(void);
char *           Tcl_GetCwd(Tcl_Interp *interp, Tcl_DString *cwdPtr);
int              Tcl_InterpDeleted(Tcl_Interp *interp);
char *           Tcl_GetString(Tcl_Obj *objPtr);
int              Tcl_EvalObjEx(Tcl_Interp *interp, Tcl_Obj *objPtr, int flags);

local interp = tcl.Tcl_CreateInterp()
local script = tcl.Tcl_NewStringObj("puts [pwd]", -1)
tcl.Tcl_EvalObjEx(interp, script, 0)

local pwd ="Tcl_DString")
tcl.Tcl_GetCwd(interp, pwd)