66
66
-- Fill in marshaller(s) for the cell.
67
67
cell.dir = ai.direction
68
cell.gtype = Type.from_typeinfo(ti)
69
if (cell.dir == (to_lua and 'in' or 'out') or cell.dir == 'inout'
70
or (to_lua and cell.dir == 'out-caller-alloc')) then
71
cell.to_lua = Value.find_marshaller(
72
cell.gtype, ti, (ai.direction == 'inout'
73
and 'none' or ti.transfer))
75
if (cell.dir == (to_lua and 'out' or 'in') or cell.dir == 'inout'
76
or (not to_lua and cell.dir == 'out-caller-alloc')) then
77
cell.to_value = Value.find_marshaller(
78
cell.gtype, ti, (ai.direction == 'inout'
79
and 'none' or ti.transfer))
68
if cell.dir == 'in' then
69
-- Direct marshalling into value.
70
cell.gtype = Type.from_typeinfo(ti)
71
local marshaller = Value.find_marshaller(cell.gtype, ti, ti.transfer)
72
cell[to_lua and 'to_lua' or 'to_value'] = marshaller
74
-- Indirect marshalling, value contains just pointer to the
75
-- real storage pointer. Used for inout and out arguments.
76
cell.gtype = Type.POINTER
77
local marshaller = Value.find_marshaller(cell.gtype)
79
if cell.dir == 'inout' then
80
function cell.to_lua(value, params)
81
local arg = marshaller(value, nil)
82
return core.marshal.argument(arg, ti, ti.transfer)
85
function cell.to_value(value, params, val)
86
local arg = marshaller(value, nil)
87
core.marshal.argument(arg, ti, ti.transfer, val)
90
function cell.to_value(value, params, val)
91
local arg, ptr = core.marshal.argument()
93
marshaller(value, nil, ptr)
94
if cell.dir == 'inout' then
95
-- Marshal input to the argument.
96
core.marshal.argument(arg, ti, ti.transfer, val)
98
-- Returning true indicates that input argument should
99
-- actually not be consumed, because we are just
100
-- preparing slot for the output value.
104
function cell.to_lua(value, params)
105
local arg = params[cell]
106
return core.marshal.argument(arg, ti, ti.transfer)
81
110
mark_array_length(cell, ti)
123
152
args[argc] = marshaller(value, marshalling_params)
125
154
-- Marshal from Lua to GValue
126
marshaller(value, marshalling_params, args[argc])
155
if marshaller(value, marshalling_params, args[argc]) then
156
-- When true is returned, we were just preparing slot for the
157
-- output value, so do not consume the argument.
128
161
-- Marshal array length output, if applicable.
129
162
if length_marshaller then
201
234
local retval = Value()
202
235
if self.ret then retval.type = self.ret.gtype end
203
236
if self.phantom then retval.type = self.phantom.gtype end
204
return retval, params, marshalling_params.keepalive
237
return retval, params, marshalling_params
207
240
-- Unmarshalls Lua restuls from Values after invoking closure or
208
241
-- signal. Returns all unmarshalled Lua values.
209
function CallInfo:post_call(params, retval)
210
local marshalling_params = { keepalive = {} }
242
function CallInfo:post_call(params, retval, marshalling_params)
243
marshalling_params.keepalive = {}
211
244
local args, argc = {}, 0
212
245
-- Check, whether phantom return exists and returned 'false'. If
213
246
-- yes, return just nil.