Call operator

Issue #14 new
Ilia Pavlovets
created an issue

I created a little modification for std::bind callbacks. But it is for void call without arguments only. I'll try to create more flexible, but I don't see beatiful solution for it.

oolua_registration.h
set_oolua_call_function<T, has_tag<Proxy_class<T>, Call_op>::Result>::set(vm, mt);
proxy_operators.h

        template<typename T>
        int lua_oolua_call(lua_State*  const vm)
        {
            T const* obj(0);
            INTERNAL::LUA_CALLED::get(vm, 1, obj);
            (*obj)();
            return 0;
        }
///
DEFINE_OOLUA_OPERATOR_FUNCTION_(oolua_call, "__call")
proxy_tags.h
    struct Call_op{};
typedef std::function<void()>   VoidCallback;

OOLUA_PROXY(VoidCallback)
    OOLUA_TAGS(No_shared, Abstract, Call_op)
OOLUA_PROXY_END

OOLUA_EXPORT_FUNCTIONS(VoidCallback)
OOLUA_EXPORT_FUNCTIONS_CONST(VoidCallback)

In app:

function CallCallback(callback)
    if callback then
        callback()
    end
end
OOLUA::Script lvm;
VoidCallback cb = std::bind(&TestClass::Test, this);
lvm.call("CallCallback", &cb);

Comments (2)

  1. Log in to comment