/* Copyright 2011 ROBLOX Corporation, All Rights Reserved */ #include "stdafx.h" #include "V8DataModel/Bindable.h" #include "FastLog.h" namespace RBX { REFLECTION_BEGIN(); const char* const sBindableFunction = "BindableFunction"; static Reflection::BoundYieldFuncDesc(shared_ptr)> func_Invoke(&BindableFunction::invoke, "Invoke", "arguments", Security::None); static Reflection::BoundAsyncCallbackDesc(shared_ptr)> callback_OnInvoke("OnInvoke", &BindableFunction::onInvoke, "arguments", &BindableFunction::processQueue); #if 0 const char* const sPropertyInstance = "Property"; static Reflection::PropDescriptor prop_Value("Value", category_Data, &PropertyInstance::getValue, &PropertyInstance::setValue, Reflection::PropertyDescriptor::SCRIPTING); static Reflection::BoundCallbackDesc callback_GetValue("OnGetValue", &PropertyInstance::getCallback); static Reflection::BoundCallbackDesc callback_SetValue("OnSetValue", &PropertyInstance::setCallback, "value"); static Reflection::EventDesc event_ValueChanged(&PropertyInstance::valueChanged, "ValueChanged", "value"); static Reflection::BoundFuncDesc func_FireValueChanged(&PropertyInstance::fireValueChanged, "FireValueChanged", Security::None); #endif const char* const sBindableEvent = "BindableEvent"; static Reflection::BoundFuncDesc)> func_Fire(&BindableEvent::fire, "Fire", "arguments", Security::None); static Reflection::EventDesc)> event_Event(&BindableEvent::event, "Event", "arguments"); REFLECTION_END(); void BindableFunction::processQueue(const OnInvokeCallback& oldValue) { if (onInvoke.empty()) return; while (!queue.empty()) { // Copy it to the stack to avoid re-entrancy bugs const Invocation invocation = queue.front(); queue.pop(); onInvoke(invocation.arguments, invocation.resumeFunction, invocation.errorFunction); } } void BindableFunction::invoke(shared_ptr arguments, boost::function)> resumeFunction, boost::function errorFunction) { if (onInvoke.empty()) { Invocation invocation = {arguments, resumeFunction, errorFunction}; queue.push(invocation); return; } onInvoke(arguments, resumeFunction, errorFunction); } bool BindableFunction::askSetParent( const Instance* instance ) const { return true; } void BindableEvent::fire( shared_ptr arguments ) { event(arguments); } bool BindableEvent::askSetParent( const Instance* instance ) const { return true; } #if 0 void PropertyInstance::fireValueChanged() { valueChanged(getCallback()); raisePropertyChanged(prop_Value); } Reflection::Variant PropertyInstance::getValue() { return getCallback(); } void PropertyInstance::setValue(const Reflection::Variant& value) { setCallback(value); } #endif } // namespace