Rename execfile -> import

This commit is contained in:
Mm2PL 2023-02-13 12:22:53 +01:00
parent 6e67890152
commit 4387e7bd69
4 changed files with 11 additions and 12 deletions

View file

@ -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...)`

View file

@ -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

View file

@ -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

View file

@ -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);