コード例 #1
0
    def __getitem__(self, idx):
        if isinstance(idx, slice):
            return Array(list(self)[idx])

        size = len(self)
        idx = size + idx if idx < 0 else idx
        if abs(idx) >= size:
            raise IndexError("list index out of range")

        gdvar = lib.godot_array_get(self._gd_ptr, idx)
        ret = variant_to_pyobj(ffi.addressof(gdvar))
        lib.godot_variant_destroy(ffi.addressof(gdvar))
        return ret
コード例 #2
0
 def bind(self, *args):
     # print('[PY->GD] Varargs call %s.%s (%s) on %s with %s' % (classname, methname, meth, self, args))
     vaargs = [
         convert_arg(meth_arg["type"], meth_arg["name"], arg, to_variant=True)
         for arg, meth_arg in zip(args, meth["args"])
     ]
     vaargs += [pyobj_to_variant(arg) for arg in args[fixargs_count:]]
     vavaargs = ffi.new("godot_variant*[]", vaargs) if vaargs else ffi.NULL
     # TODO: use `godot_variant_call_error` to raise exceptions
     varret = lib.godot_method_bind_call(
         methbind, self._gd_ptr, vavaargs, len(args), ffi.NULL
     )
     ret = variant_to_pyobj(ffi.addressof(varret))
     lib.godot_variant_destroy(ffi.addressof(varret))
     # print('[PY->GD] returned:', ret)
     return ret
コード例 #3
0
 def __getitem__(self, key):
     var = pyobj_to_variant(key)
     gdvar = lib.godot_dictionary_get(self._gd_ptr, var)
     ret = variant_to_pyobj(ffi.addressof(gdvar))
     lib.godot_variant_destroy(ffi.addressof(gdvar))
     return ret
コード例 #4
0
 def pop_front(self):
     gdvar = lib.godot_array_pop_front(self._gd_ptr)
     ret = variant_to_pyobj(ffi.addressof(gdvar))
     lib.godot_variant_destroy(ffi.addressof(gdvar))
     return ret