aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-01-21 00:12:41 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2015-01-21 00:12:41 +0100
commitd8ecd402c9fffe7555d339d500f7525f5703ef58 (patch)
treeec855ab55a341376657f9df09887a0b174f7cf39
parent8ecdab1ddd84086b2d7a0e1552eccbd1a869308c (diff)
downloadponymap-d8ecd402c9fffe7555d339d500f7525f5703ef58.tar.gz
ponymap-d8ecd402c9fffe7555d339d500f7525f5703ef58.tar.xz
ponymap-d8ecd402c9fffe7555d339d500f7525f5703ef58.zip
Introduce Lua API version checking
-rw-r--r--plugins/lua-loader.c24
-rw-r--r--plugins/socks.lua2
2 files changed, 21 insertions, 5 deletions
diff --git a/plugins/lua-loader.c b/plugins/lua-loader.c
index 341327b..3fc38e9 100644
--- a/plugins/lua-loader.c
+++ b/plugins/lua-loader.c
@@ -29,6 +29,8 @@
#include <lualib.h>
#include <lauxlib.h>
+#define XLUA_API_VERSION 1 ///< Version of the Lua API
+
// --- Utilities ---------------------------------------------------------------
static struct plugin_data
@@ -63,13 +65,13 @@ xlua_panic (lua_State *L)
// --- Unit wrapper ------------------------------------------------------------
+#define UNIT_METATABLE "unit" ///< Identifier for the Lua metatable
+
struct unit_wrapper
{
struct unit *unit; ///< The underlying unit
};
-#define UNIT_METATABLE "unit"
-
static int
xlua_unit_get_address (lua_State *L)
{
@@ -341,11 +343,21 @@ xlua_get_config (lua_State *L)
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[] =
{
- { "register_service", xlua_register_service },
- { "get_config", xlua_get_config },
- { NULL, NULL }
+ { "register_service", xlua_register_service },
+ { "get_config", xlua_get_config },
+ { "check_api_version", xlua_check_api_version },
+ { NULL, NULL }
};
static bool
@@ -403,6 +415,8 @@ initialize (void *ctx, struct plugin_api *api)
luaL_newlib (L, xlua_library);
lua_pushinteger (L, 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);
// Create a metatable for the units
diff --git a/plugins/socks.lua b/plugins/socks.lua
index 8497bbb..9835f04 100644
--- a/plugins/socks.lua
+++ b/plugins/socks.lua
@@ -19,6 +19,8 @@
-- This plugin serves as an example of how to write Lua plugins for ponymap
+ponymap.check_api_version (1)
+
-- SOCKS 4
local Socks4 = {}