예제 #1
0
 def get_parent_class(cls, classname):
     ret = godot_string_alloc()
     lib.godot_string_new(ret)
     gd_classname = godot_string_from_pyobj(classname)
     args = ffi.new("godot_string**", gd_classname)
     lib.godot_method_bind_ptrcall(cls._meth_get_parent_class,
                                   cls._instance, ffi.cast("void**",
                                                           args), ret)
     raw_str = lib.godot_string_wide_str(ret)
     return ffi.string(raw_str)
예제 #2
0
def pybind_get_signal_list(handle):
    # Lazily generate the list of exported properties' names
    cls_or_instance = ffi.from_handle(handle)
    cls = cls_or_instance if isinstance(cls_or_instance,
                                        type) else type(cls_or_instance)
    # Need to store the cached list with a per-class name to avoid shadowing
    # from a parent class
    field = '_%s__signal_raw_list' % cls.__name__
    raw_list = getattr(cls, field, None)
    if not raw_list:
        # Build the list of signals, ready to be access by godot
        raw_list = ffi.new('godot_string[]', len(cls.__signals) + 1)
        for i, name in enumerate(cls.__signals.keys()):
            lib.godot_string_new_unicode_data(ffi.addressof(raw_list[i]), name,
                                              -1)
        # Last entry is an empty string
        lib.godot_string_new(ffi.addressof(raw_list[len(cls.__signals)]))
        setattr(cls, field, raw_list)
    return raw_list
예제 #3
0
def pybind_get_meth_list(handle):
    # Lazily generate the list of methods' names
    cls_or_instance = ffi.from_handle(handle)
    cls = cls_or_instance if isinstance(cls_or_instance,
                                        type) else type(cls_or_instance)
    # Need to store the cached list with a per-class name to avoid shadowing
    # from a parent class
    field = '_%s__meth_raw_list' % cls.__name__
    raw_list = getattr(cls, field, None)
    if not raw_list:
        meths = [
            k for k in dir(cls)
            if not k.startswith('__') and callable(getattr(cls, k))
        ]
        raw_list = ffi.new('godot_string[]', len(meths) + 1)
        for i, name in enumerate(meths):
            lib.godot_string_new_unicode_data(ffi.addressof(raw_list[i]), name,
                                              -1)
        # Last entry is an empty string
        lib.godot_string_new(ffi.addressof(raw_list[len(meths)]))
        setattr(cls, field, raw_list)
    return raw_list