Commit 794c7ba8 authored by Marek Vavruša's avatar Marek Vavruša

daemon: attempt at using versioned libraries

parent 7ffd3e4a
......@@ -15,6 +15,7 @@
*/
#include <ccan/json/json.h>
#include <ccan/asprintf/asprintf.h>
#include <uv.h>
#include <unistd.h>
#include <libknot/internal/mempattern.h>
......@@ -60,6 +61,26 @@ static int l_help(lua_State *L)
return 1;
}
/** Return platform-specific versioned library name. */
static int l_libpath(lua_State *L)
{
int n = lua_gettop(L);
if (n < 2)
return 0;
auto_free char *lib_path = NULL;
const char *lib_name = lua_tostring(L, 1);
const char *lib_version = lua_tostring(L, 2);
#if defined(__APPLE__)
lib_path = afmt("%s.%s.dylib", lib_name, lib_version);
#elif _WIN32
lib_path = afmt("%s.dll", lib_name); /* Versioned in RC files */
#else
lib_path = afmt("%s.so.%s", lib_name, lib_version);
#endif
lua_pushstring(L, lib_path);
return 1;
}
/** Quit current executable. */
static int l_quit(lua_State *L)
{
......@@ -302,6 +323,8 @@ static int init_state(struct engine *engine)
lua_setglobal(engine->L, "verbose");
lua_pushcfunction(engine->L, l_option);
lua_setglobal(engine->L, "option");
lua_pushcfunction(engine->L, l_libpath);
lua_setglobal(engine->L, "libpath");
lua_pushlightuserdata(engine->L, engine);
lua_setglobal(engine->L, "__engine");
return kr_ok();
......
......@@ -6,7 +6,7 @@ local bit = require('bit')
local bor = bit.bor
local band = bit.band
local C = ffi.C
local knot = ffi.load('knot')
local knot = ffi.load(libpath('libknot', '1'))
ffi.cdef[[
/*
......
......@@ -3,7 +3,7 @@
--
local ffi = require('ffi')
local libzscanner = ffi.load('zscanner')
local libzscanner = ffi.load(libpath('libzscanner', '0'))
ffi.cdef[[
/*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment