Skip to content

Commit

Permalink
Add support for loading Lua modules from script-modules
Browse files Browse the repository at this point in the history
  • Loading branch information
gnome-mpv committed Nov 5, 2024
1 parent 5a700b3 commit aecc0f3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/celluloid-application.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ initialize_gui(CelluloidApplication *app);
static void
create_dirs(void);

static void
set_lua_path(void);

static gboolean
shutdown_signal_handler(gpointer data);

Expand Down Expand Up @@ -224,6 +227,30 @@ create_dirs()
g_free(watch_dir);
}

static void
set_lua_path()
{
const gchar *old_lua_path = g_getenv("LUA_PATH");
gchar *new_lua_path = NULL;
gchar *modules = get_script_modules_dir_path();

if(old_lua_path)
{
new_lua_path =
g_strdup_printf("%s/?.lua;%s", modules, old_lua_path);
}
else
{
new_lua_path =
g_strdup_printf("%s/?.lua;;", modules);
}

g_setenv("LUA_PATH", new_lua_path, TRUE);

g_free(modules);
g_free(new_lua_path);
}

static gboolean
shutdown_signal_handler(gpointer data)
{
Expand Down Expand Up @@ -457,6 +484,8 @@ startup_handler(GApplication *gapp, gpointer data)
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);
create_dirs();
set_lua_path();


g_info("Starting Celluloid " VERSION);
}
Expand Down
9 changes: 9 additions & 0 deletions src/celluloid-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ get_script_opts_dir_path(void)
NULL );
}

gchar *
get_script_modules_dir_path(void)
{
return g_build_filename( g_get_user_config_dir(),
CONFIG_DIR,
"script-modules",
NULL );
}

gchar *
get_watch_dir_path(void)
{
Expand Down
3 changes: 3 additions & 0 deletions src/celluloid-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ get_scripts_dir_path(void);
gchar *
get_script_opts_dir_path(void);

gchar *
get_script_modules_dir_path(void);

gchar *
get_watch_dir_path(void);

Expand Down

0 comments on commit aecc0f3

Please sign in to comment.