From 4387e7bd69794bae8cf62644b1c6e0d32dc1a1bc Mon Sep 17 00:00:00 2001 From: Mm2PL Date: Mon, 13 Feb 2023 12:22:53 +0100 Subject: [PATCH] Rename execfile -> import --- docs/wip-plugins.md | 12 ++++++------ src/controllers/plugins/LuaAPI.cpp | 2 +- src/controllers/plugins/LuaAPI.hpp | 2 +- src/controllers/plugins/PluginController.cpp | 7 +++---- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/docs/wip-plugins.md b/docs/wip-plugins.md index cb3da42d2..16b582403 100644 --- a/docs/wip-plugins.md +++ b/docs/wip-plugins.md @@ -17,7 +17,7 @@ Chatterino Plugins dir/ └── info.json ``` -`init.lua` will be the file loaded when the plugin is enabled. You may load other files using [`execfile` global function](#execfilefilename=). +`init.lua` will be the file loaded when the plugin is enabled. You may load other files using [`import` global function](#importfilename=). `info.json` contains metadata about the plugin, like its name, description, authors, homepage link, tags, version, license name. The version field **must** @@ -151,7 +151,7 @@ It achieves this by forcing all inputs to be encoded with `UTF-8`. See [official documentation](https://www.lua.org/manual/5.4/manual.html#pdf-load) -#### `execfile(filename)` +#### `import(filename)` This function mimics Lua's `dofile` however relative paths are relative to your plugin's directory. You are restricted to loading files in your plugin's directory. You cannot load files with bytecode inside. @@ -159,10 +159,10 @@ You are restricted to loading files in your plugin's directory. You cannot load Example: ```lua -execfile("stuff.lua") -- executes Plugins/name/stuff.lua -execfile("./stuff.lua") -- executes Plugins/name/stuff.lua -execfile("../stuff.lua") -- tries to load Plugins/stuff.lua and errors -execfile("luac.out") -- tried to load Plugins/name/luac.out and errors because it contains non-utf8 data +import("stuff.lua") -- executes Plugins/name/stuff.lua +import("./stuff.lua") -- executes Plugins/name/stuff.lua +import("../stuff.lua") -- tries to load Plugins/stuff.lua and errors +import("luac.out") -- tried to load Plugins/name/luac.out and errors because it contains non-utf8 data ``` #### `print(Args...)` diff --git a/src/controllers/plugins/LuaAPI.cpp b/src/controllers/plugins/LuaAPI.cpp index b6ba100db..2e9d660ff 100644 --- a/src/controllers/plugins/LuaAPI.cpp +++ b/src/controllers/plugins/LuaAPI.cpp @@ -206,7 +206,7 @@ int g_load(lua_State *L) # endif } -int g_dofile(lua_State *L) +int g_import(lua_State *L) { auto countArgs = lua_gettop(L); // Lua allows dofile() which loads from stdin, but this is very useless in our case diff --git a/src/controllers/plugins/LuaAPI.hpp b/src/controllers/plugins/LuaAPI.hpp index 859a6a67b..5075bec6c 100644 --- a/src/controllers/plugins/LuaAPI.hpp +++ b/src/controllers/plugins/LuaAPI.hpp @@ -17,7 +17,7 @@ int g_load(lua_State *L); int g_print(lua_State *L); // this one is exposed as execfile -int g_dofile(lua_State *L); +int g_import(lua_State *L); // NOLINTEND(readability-identifier-naming) // Exposed as c2.LogLevel diff --git a/src/controllers/plugins/PluginController.cpp b/src/controllers/plugins/PluginController.cpp index 62c3be8f7..1e59f51ae 100644 --- a/src/controllers/plugins/PluginController.cpp +++ b/src/controllers/plugins/PluginController.cpp @@ -182,11 +182,10 @@ void PluginController::openLibrariesFor(lua_State *L, // NOLINTNEXTLINE(*-avoid-c-arrays) static const luaL_Reg replacementFuncs[] = { {"load", lua::api::g_load}, - - // chatterino dofile is way more similar to require() than dofile() - {"execfile", lua::api::g_dofile}, - {"print", lua::api::g_print}, + + // This function replaces both `dofile` and `require`, see docs/wip-plugins.md for more info + {"import", lua::api::g_import}, {nullptr, nullptr}, }; luaL_setfuncs(L, replacementFuncs, 0);