From 0ff3abae626ee22010d274bc81f9bb90fbe93ef7 Mon Sep 17 00:00:00 2001 From: "Franklin \"Snaipe\" Mathieu" Date: Wed, 9 Nov 2016 13:27:55 +0100 Subject: [PATCH] dsl: Make packets support 'args' special variable --- src/wssdl/core.lua | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/wssdl/core.lua b/src/wssdl/core.lua index 2e50161..debecd6 100644 --- a/src/wssdl/core.lua +++ b/src/wssdl/core.lua @@ -30,6 +30,20 @@ local initenv = function () wssdl.env, wssdl.fenv = debug.getfenv(4) end +local function get_params(...) + local params = {...} + if #params == 1 and type(params[1]) == 'table' then + params = params[1] + end + if params.args == nil then + params.args = {} + for i, v in ipairs(params) do + params.args[i] = v + params[i] = nil + end + end +end + wssdl._alias = { _create = function(pkt, def) @@ -39,17 +53,7 @@ wssdl._alias = { _field = def[1], _imbue = function (target, ...) - local params = {...} - if #params == 1 and type(params[1]) == 'table' then - params = params[1] - end - if params.args == nil then - params.args = {} - for i, v in ipairs(params) do - params.args[i] = v - params[i] = nil - end - end + local params = get_params(...) local field = utils.deepcopy(alias._field):_eval(params) -- Don't copy fields in the blacklist @@ -86,7 +90,8 @@ wssdl._packet = { _properties = pkt._properties, _imbue = function (field, ...) - local pkt = newpacket:eval({...}) + local params = get_params(...) + local pkt = newpacket:eval(params) field._type = "packet" field._packet = pkt return field