library: api_close

This commit is contained in:
Adam
2024-10-04 14:30:38 +01:00
parent df66cd0d49
commit dfd3fcada6
2 changed files with 17 additions and 1 deletions

View File

@@ -275,9 +275,10 @@ void _bolt_plugin_init(const struct PluginManagedFunctions* functions) {
}
static int _bolt_api_init(lua_State* state) {
lua_createtable(state, 0, 18);
lua_createtable(state, 0, 19);
API_ADD(apiversion)
API_ADD(checkversion)
API_ADD(close)
API_ADD(time)
API_ADD(datetime)
API_ADD(weekday)
@@ -1009,6 +1010,16 @@ static int api_checkversion(lua_State* state) {
return 2;
}
static int api_close(lua_State* state) {
lua_getfield(state, LUA_REGISTRYINDEX, PLUGIN_REGISTRYNAME);
const struct Plugin* plugin = lua_touserdata(state, -1);
const uint64_t id = plugin->id;
lua_pop(state, 1);
_bolt_plugin_stop(id);
_bolt_plugin_notify_stopped(id);
return 0;
}
static int api_time(lua_State* state) {
_bolt_check_argc(state, 0, "time");
#if defined(_WIN32)

View File

@@ -55,6 +55,11 @@ static int api_apiversion(lua_State*);
/// For compatibility reasons, there will never be a breaking change to this function.
static int api_checkversion(lua_State*);
/// [-0, +0, -]
/// Stops this instance of this plugin. Any resources will be cleaned up and destroyed. Do not use
/// any API functions after this one.
static int api_close(lua_State*);
/// [-0, +1, -]
/// Returns a monotonic time as an integer, in microseconds.
///