~ubuntu-branches/ubuntu/wily/lua-lgi/wily-proposed

« back to all changes in this revision

Viewing changes to lgi/override/GObject-Closure.lua

  • Committer: Package Import Robot
  • Author(s): Enrico Tassi
  • Date: 2012-06-25 13:36:04 UTC
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: package-import@ubuntu.com-20120625133604-3v03ss7t7cwdmp6z
Tags: upstream-0.7.1
ImportĀ upstreamĀ versionĀ 0.7.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
 
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))
74
 
      end
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
 
73
      else
 
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)
 
78
         if to_lua then
 
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)
 
83
               end
 
84
            end
 
85
            function cell.to_value(value, params, val)
 
86
               local arg = marshaller(value, nil)
 
87
               core.marshal.argument(arg, ti, ti.transfer, val)
 
88
            end
 
89
         else
 
90
            function cell.to_value(value, params, val)
 
91
               local arg, ptr = core.marshal.argument()
 
92
               params[cell] = arg
 
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)
 
97
               else
 
98
                  -- Returning true indicates that input argument should
 
99
                  -- actually not be consumed, because we are just
 
100
                  -- preparing slot for the output value.
 
101
                  return true
 
102
               end
 
103
            end
 
104
            function cell.to_lua(value, params)
 
105
               local arg = params[cell]
 
106
               return core.marshal.argument(arg, ti, ti.transfer)
 
107
            end
 
108
         end
80
109
      end
81
110
      mark_array_length(cell, ti)
82
111
 
123
152
      args[argc] = marshaller(value, marshalling_params)
124
153
   else
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.
 
158
         argc = argc - 1
 
159
      end
127
160
 
128
161
      -- Marshal array length output, if applicable.
129
162
      if length_marshaller then
155
188
      -- Do the call.
156
189
      args = { target(unpack(args, 1, argc)) }
157
190
      argc = 0
158
 
      marshalling_params = { keepalive = {} }
 
191
      marshalling_params.keepalive = {}
159
192
 
160
193
      -- Marshall the return value.
161
194
      if self.ret and retval 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
205
238
end
206
239
 
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.