Skip to content

Commit

Permalink
Use semicolon as file path separator for lua_load
Browse files Browse the repository at this point in the history
Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
  • Loading branch information
Caellian committed Feb 3, 2025
1 parent 35c5a05 commit d52a0fd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
13 changes: 12 additions & 1 deletion doc/config_settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,18 @@ values:
- function_name
- [function arguments]
- name: lua_load
desc: Loads the Lua scripts separated by spaces.
desc: |-
List of lua script paths to load at startup in order to provide lua
functions for other hooks. Listed files are loaded (executed) before
'lua_startup_hook' and can (but shouldn't) run code in global scope.
Paths are ';' (semicolon) separated, and can be relative to the config
file path, or absolute.
The paths were previously ' ' (space) separated, this functionality is
still supported if ';' isn't found, but is deprecated and will be removed
in future versions. Empty paths are skipped so './example file.lua;' is
valid.
- name: lua_mouse_hook
desc: |-
This function, if defined, will be called by Conky upon receiving mouse
Expand Down
30 changes: 22 additions & 8 deletions src/lua/llua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
*/
#include "config.h"

#include "build.h"
#include <cstring>
#include "../conky.h"
#include "../geometry.h"
#include "llua.h"
#include "../logging.h"
#include "build.h"
#include "llua.h"

#ifdef BUILD_GUI
#include "../output/gui.h"
Expand Down Expand Up @@ -75,13 +76,26 @@ class lua_load_setting : public conky::simple_config_setting<std::string> {

if (init) {
std::string files = do_convert(l, -1).first;
while (!files.empty()) {
std::string::size_type pos = files.find(' ');
if (pos > 0) {
std::string file(files, 0, pos);
llua_load(file.c_str());

// Split file names into separate `\0` strings
if (files.find(';') != std::string::npos) {
for (auto &ch : files) {
if (ch == ';') { ch = '\0'; }
}
} else {
// TODO: Remove space-delimited file name handling in 3 years (2028.)
for (auto &ch : files) {
if (ch == ' ') { ch = '\0'; }
}
}

const char *start = files.c_str();
const char *end = start + files.size();
while (start < end) {
if (start != '\0') { // Skip empty strings
llua_load(start);
}
files.erase(0, pos == std::string::npos ? pos : pos + 1);
start += strlen(start) + 1;
}
}

Expand Down

0 comments on commit d52a0fd

Please sign in to comment.