From 105def26a82a20070b421e7f3d234f10604b427f Mon Sep 17 00:00:00 2001
From: Dmitry Simonenko <pmwkaa@gmail.com>
Date: Thu, 26 Apr 2012 18:03:26 +0400
Subject: [PATCH] lua-noffireq: moved loading the ffi module from box.lua

---
 mod/box/box.lua     |  2 --
 src/tarantool_lua.m | 11 +++++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/mod/box/box.lua b/mod/box/box.lua
index 205bc8e20f..ecd45619c3 100644
--- a/mod/box/box.lua
+++ b/mod/box/box.lua
@@ -328,8 +328,6 @@ if initfile ~= nil then
     io.close(initfile)
     dofile("init.lua")
 end
--- 64bit operations support, etc.
-ffi = require("ffi")
 -- security: nullify some of the most serious os.* holes
 --
 os.execute = nil
diff --git a/src/tarantool_lua.m b/src/tarantool_lua.m
index 3bc2befd1e..b7126d4147 100644
--- a/src/tarantool_lua.m
+++ b/src/tarantool_lua.m
@@ -902,6 +902,15 @@ tarantool_lua_register_type(struct lua_State *L, const char *type_name,
 	lua_pop(L, 1);
 }
 
+/** A helper to preload a lua modules. */
+static int
+tarantool_lua_require(lua_State *L, char *name)
+{
+	lua_getglobal(L, "require");
+	lua_pushstring(L, name);
+	return lua_pcall(L, 1, 0, 0);
+}
+
 struct lua_State *
 tarantool_lua_init()
 {
@@ -909,6 +918,8 @@ tarantool_lua_init()
 	if (L == NULL)
 		return L;
 	luaL_openlibs(L);
+	if (tarantool_lua_require(L, "ffi") != 0)
+		panic("%s", lua_tostring(L, -1));
 	luaL_register(L, boxlib_name, boxlib);
 	lua_pop(L, 1);
 	luaL_register(L, fiberlib_name, fiberlib);
-- 
GitLab