Rework plugin architecture #3

Merged
lucas merged 2 commits from feat/plugin-architecture into master 2025-05-08 13:48:57 +02:00
2 changed files with 16 additions and 9 deletions
Showing only changes of commit 6042441275 - Show all commits

View file

@ -69,7 +69,7 @@ typedef void *(*GetApiFunction)(unsigned api);
struct PluginApi {
#ifdef __cplusplus
uint32_t version = 65;
uint32_t version = 69;
uint32_t flags = 3; // lua plugin
#else
uint32_t version;
@ -83,13 +83,19 @@ struct PluginApi {
loaded. */
void (*loaded)(GetApiFunction get_engine_api);
// Seemingly not called by current versions of the engine, at least in release
// mode.
/* Called at the start of a "hot reload" of the plugin DLL. Should return a
pointer to a serialized "state" for the plugin.*/
void *(*start_reload)(GetApiFunction get_engine_api);
// Seemingly not called by current versions of the engine, at least in release
// mode.
/* Called just before the plugin is unloaded. */
void (*unloaded)();
// Seemingly not called by current versions of the engine, at least in release
// mode.
/* Called to finalized the "hot reload" after the plugin has been reloaded
with the new code. Should restore the state from the serialized state data.
Note that it is the responsibility of the plugin to free the state data. */
@ -223,9 +229,8 @@ struct LuaApi {
int (*checkstack)(lua_State *L, int sz);
void (*xmove)(lua_State *from, lua_State *to, int n);
const void *(*fnx1)(lua_State *L, int idx);
/* Access functions */
int (*isnil)(lua_State *L, int idx);
int (*isnumber)(lua_State *L, int idx);
int (*isstring)(lua_State *L, int idx);
int (*iscfunction)(lua_State *L, int idx);
@ -313,8 +318,6 @@ struct LuaApi {
int (*gethookmask)(lua_State *L);
int (*gethookcount)(lua_State *L);
// int (*fnx3) (lua_State* L);
/* Library functions */
void (*lib_openlib)(lua_State *L, const char *libname, const luaL_Reg *l,
int nup);
@ -399,6 +402,8 @@ struct LuaApi {
/* Gets a Unit at the specified index. */
CApiUnit *(*getunit)(lua_State *L, int i);
void *(*getunknown)(lua_State *L, int i);
/* Gets the Lua state where the main scripts execute. */
lua_State *(*getscriptenvironmentstate)();
@ -423,8 +428,10 @@ struct LuaApi {
/* Returns true if the stack entry is a UnitReference. */
int (*isunitreference)(lua_State *L, int i);
size_t (*objlen2)(lua_State *L, int idx);
/* Reserved for expansion of the API. */
void *reserved[32];
// void *reserved[30];
};
struct LoggingApi {

View file

@ -13,16 +13,16 @@ use std::ffi::CString;
use std::os::raw::c_char;
use std::os::raw::c_void;
use bindings::lua_CFunction;
pub use bindings::lua_State;
pub use bindings::GetApiFunction;
pub use bindings::PluginApi;
pub use bindings::PluginApiID;
use bindings::lua_CFunction;
pub use bindings::lua_State;
impl std::default::Default for PluginApi {
fn default() -> Self {
Self {
version: 65,
version: 69,
flags: 3,
setup_game: None,
update_game: None,