Introduce Lua API version checking
This commit is contained in:
parent
8ecdab1ddd
commit
d8ecd402c9
|
@ -29,6 +29,8 @@
|
||||||
#include <lualib.h>
|
#include <lualib.h>
|
||||||
#include <lauxlib.h>
|
#include <lauxlib.h>
|
||||||
|
|
||||||
|
#define XLUA_API_VERSION 1 ///< Version of the Lua API
|
||||||
|
|
||||||
// --- Utilities ---------------------------------------------------------------
|
// --- Utilities ---------------------------------------------------------------
|
||||||
|
|
||||||
static struct plugin_data
|
static struct plugin_data
|
||||||
|
@ -63,13 +65,13 @@ xlua_panic (lua_State *L)
|
||||||
|
|
||||||
// --- Unit wrapper ------------------------------------------------------------
|
// --- Unit wrapper ------------------------------------------------------------
|
||||||
|
|
||||||
|
#define UNIT_METATABLE "unit" ///< Identifier for the Lua metatable
|
||||||
|
|
||||||
struct unit_wrapper
|
struct unit_wrapper
|
||||||
{
|
{
|
||||||
struct unit *unit; ///< The underlying unit
|
struct unit *unit; ///< The underlying unit
|
||||||
};
|
};
|
||||||
|
|
||||||
#define UNIT_METATABLE "unit"
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
xlua_unit_get_address (lua_State *L)
|
xlua_unit_get_address (lua_State *L)
|
||||||
{
|
{
|
||||||
|
@ -341,10 +343,20 @@ xlua_get_config (lua_State *L)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
xlua_check_api_version (lua_State *L)
|
||||||
|
{
|
||||||
|
lua_Integer requested = luaL_checkinteger (L, 1);
|
||||||
|
if (requested != XLUA_API_VERSION)
|
||||||
|
return luaL_error (L, "incompatible API version");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static luaL_Reg xlua_library[] =
|
static luaL_Reg xlua_library[] =
|
||||||
{
|
{
|
||||||
{ "register_service", xlua_register_service },
|
{ "register_service", xlua_register_service },
|
||||||
{ "get_config", xlua_get_config },
|
{ "get_config", xlua_get_config },
|
||||||
|
{ "check_api_version", xlua_check_api_version },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -403,6 +415,8 @@ initialize (void *ctx, struct plugin_api *api)
|
||||||
luaL_newlib (L, xlua_library);
|
luaL_newlib (L, xlua_library);
|
||||||
lua_pushinteger (L, SERVICE_SUPPORTS_TLS);
|
lua_pushinteger (L, SERVICE_SUPPORTS_TLS);
|
||||||
lua_setfield (L, -2, "SERVICE_SUPPORTS_TLS");
|
lua_setfield (L, -2, "SERVICE_SUPPORTS_TLS");
|
||||||
|
lua_pushinteger (L, XLUA_API_VERSION);
|
||||||
|
lua_setfield (L, -2, "api_version");
|
||||||
lua_setglobal (L, PROGRAM_NAME);
|
lua_setglobal (L, PROGRAM_NAME);
|
||||||
|
|
||||||
// Create a metatable for the units
|
// Create a metatable for the units
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
-- This plugin serves as an example of how to write Lua plugins for ponymap
|
-- This plugin serves as an example of how to write Lua plugins for ponymap
|
||||||
|
|
||||||
|
ponymap.check_api_version (1)
|
||||||
|
|
||||||
-- SOCKS 4
|
-- SOCKS 4
|
||||||
|
|
||||||
local Socks4 = {}
|
local Socks4 = {}
|
||||||
|
|
Loading…
Reference in New Issue