bin: bundle used luajit ffi bindings

In the C code we now also look for lua packages in the install path for GEGL
lua files.
parent c227abe1
This diff is collapsed.
This diff is collapsed.
local M = {}
-- the api is possible to replace with something
-- that sniffs magic, this is the simplest thing
-- that almost works though
function M.for_path(path)
if path:match("mrl-") then
return "application/mmm"
end
if path:match("mmm-") then
return "application/mmm"
end
if path:match("mrg-") then
return "application/mmm"
end
if path:has_suffix(".mp4") then
return "video/mpeg4"
elseif path:has_suffix(".ogv") then
return "video/ogv"
elseif path:has_suffix(".mpg") then
return "video/mpeg"
end
if path:has_prefix("/proc/") then
return "text/plain"
elseif path:has_suffix(".gif") or
path:has_suffix(".GIF") then
return "image/gif";
elseif path:has_suffix(".png") or
path:has_suffix(".PNG") then
return "image/png"
elseif path:has_suffix(".svg") or
path:has_suffix(".SVG") then
return "image/svg"
elseif path:has_suffix(".html") or
path:has_suffix(".HTML") then
return "text/html"
elseif path:has_suffix(".jpg") or
path:has_suffix(".jpeg") or
path:has_suffix(".JPEG") or
path:has_suffix(".JPG")
then
return "image/jpeg"
elseif path:has_suffix("README") or
path:has_suffix(".txt") or
path:has_suffix("Makefile") or
path:has_suffix("Makefile.am") or
path:has_suffix("configure") or
path:has_suffix('.c') or
path:has_suffix('.js') or
path:has_suffix('.md') or
path:has_suffix('.pc') or
path:has_suffix('.inc') or
path:has_suffix('.h') or
path:has_suffix('.css')
-- or
-- path:has_suffix(".lua")
then
return "text/plain"
end
io.input(path)
document = io.read("*line")
io.close()
if document and document:match("luajit") then
return "application/mmm"
end
return "text/plain"
end
return M
This diff is collapsed.
local Mrg = require('mrg')
local M = {}
local S = require('syscall')
function M.serialize (o)
if type(o) == "number" then return o
elseif type(o) == "nil" then return "nil"
elseif type(o) == "boolean" then
if o == true then
return "true" else
return "false"
end
elseif type(o) == "string" then return string.format("%q", o)
elseif type(o) == "table" then
local ret = "{"
for k,v in pairs(o) do
ret = ret .. k .. '=' .. M.serialize(v) .. ','
end
ret = ret .. '}'
return ret
else
error("cannot serialize a " .. type(o))
end
end
---------------
local in_modal = false
local modal_x, modal_y = 100, 100
local modal_choices={}
local modal_string=nil
function M.modal(mrg, x, y, choices)
if choices then
modal_choices = choices
else
modal_choices = {}
end
local w, h = 100, 100
if x < w/2 then x = w/2 end
if y < h/2 then y = h/2 end
if x > mrg:width() - w/2 then x = mrg:width ()-w/2 end
if y > mrg:height() - h/2 then y = mrg:height()-h/2 end
modal_x = x
modal_y = y
in_modal = true
modal_string = nil
mrg:set_cursor_pos(0)
mrg:queue_draw(nil)
end
function M.modal_end(mrg)
in_modal = false
mrg:queue_draw(nil)
end
function M.modal_draw(mrg)
if not in_modal then return end
local cr = mrg:cr()
-- block out all other events, making clicking outside cancel
cr:rectangle (0,0,mrg:width(),mrg:height())
cr:set_source_rgba(0,0,0,0.5)
mrg:listen(Mrg.COORD, function(event)
event:stop_propagate()
end)
mrg:listen(Mrg.TAP, function(event)
M.modal_end (mrg)
end)
cr:fill()
cr:rectangle (modal_x - 50, modal_y - 50, 100, 100)
cr:set_source_rgba(0,0,0, 0.5)
mrg:listen(Mrg.COORD, function(event)
event:stop_propagate()
end)
cr:fill()
mrg:set_edge_left(modal_x - 50)
mrg:set_edge_top(modal_y - 50)
mrg:set_style('background:transparent; color: white; ')
for i,v in pairs(modal_choices) do
mrg:text_listen(Mrg.TAP, function(event)
if v.cb and v.type ~= 'edit' then
M.modal_end (mrg)
v.cb()
end
mrg:queue_draw(nil)
end)
if v.type == 'edit' then
mrg:edit_start(function(new_text)
modal_string = new_text
end)
if modal_string then
mrg:print(modal_string)
else
mrg:print(v.title )
end
mrg:edit_end()
mrg:add_binding("return", NULL, NULL,
function (event)
if modal_string then
v.cb (modal_string) -- print ('return!!')
modal_string = nil
end
event:stop_propagate()
end)
else
mrg:print(v.title )
end
mrg:print("\n")
mrg:text_listen_done ()
end
end
function M.which(command)
local ret = ''
local PATH = '.:' .. S.getenv('PATH')
for str in string.gmatch(PATH, "([^:]+)") do
if S.stat(str .. '/' .. command) then
local cmpstr = str
if cmpstr == '.' then cmpstr = S.getcwd() end
return cmpstr .. '/' .. command
end
end
return nil
end
function string.has_suffix(String,End)
return End=='' or string.sub(String,-string.len(End))==End
end
function string.has_prefix(String,Start)
return string.sub(String,1,string.len(Start))==Start
end
return M
......@@ -843,12 +843,35 @@ int mrg_ui_main (int argc, char **argv, char **ops)
{
int status, result;
char *init_path = resolve_lua_file ("init.lua");
const char * const *data_dirs = g_get_system_data_dirs ();
L = luaL_newstate ();
luaL_openlibs(L);
/* expose o as a global light user data for luajit ffi interactions */
lua_pushlightuserdata (L, o);
lua_setglobal(L, "STATE");
/* set up package path to permit using mrg, mmm and cairo ffi bindings
we ship with, making it easier to get all dependencies sorted.
*/
status = luaL_loadstring(L, "package.path = package.path .. ';./lua/?.lua'\n"
);
result = lua_pcall(L, 0, LUA_MULTRET, 0);
if (result){
fprintf (stderr, "lua exec problem %s\n", lua_tostring(L, -1));
}
for (int i = 0; data_dirs[i]; i++)
{
char *script = g_strdup_printf ("package.path = package.path .. ';%s/gegl-0.4/lua/?.lua'\n", data_dirs[i]);
status = luaL_loadstring(L, script);
result = lua_pcall(L, 0, LUA_MULTRET, 0);
if (result){
fprintf (stderr, "lua exec problem %s\n", lua_tostring(L, -1));
}
}
if (init_path)
{
status = luaL_loadfile(L, init_path);
......
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