Skip to content

Commit

Permalink
dsl: Make packets support 'args' special variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Snaipe committed Nov 9, 2016
1 parent 5abddd1 commit 0ff3aba
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/wssdl/core.lua
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0ff3aba

Please sign in to comment.