Example #1
0
void LuaScriptInstance::ApplyAttributes()
{
    WeakPtr<LuaFunction> function = scriptObjectMethods_[LSOM_APPLYATTRIBUTES];
    if (function && function->BeginCall(this))
    {
        function->EndCall();
    }
}
Example #2
0
		/*=============================================================================
		-- Adds the object to the inventory. Effectively "picking up" the object.
		=============================================================================*/
		void Actor::HoldObject(WeakPtr<Object> object)
		{
			if (!object.expired())
			{
				mInventory->AddObject(object);
				object.lock()->SetHost( GetManager()->GetEntity(GetId()) );
			}
		}
void PushWeakObject(duk_context* ctx, Object* object)
{
    if (!object)
    {
        duk_push_null(ctx);
        return;
    }

    duk_push_heap_stash(ctx);

    // Check if the wrapper for the object already exists in stash
    // This is required so that comparisons of object references (e.g. against the me property) work properly
    if (duk_has_prop_index(ctx, -1, (size_t)object))
    {
        duk_get_prop_index(ctx, -1, (size_t)object);
        WeakPtr<Object>* oldPtr = GetWeakPtr(ctx, -1);
        if (oldPtr && oldPtr->Get() == object)
        {
            duk_remove(ctx, -2); // Remove stash
            return;
        }
        else
            duk_pop(ctx); // Valid existing wrapper not found
    }

    duk_push_object(ctx);
    WeakPtr<Object>* ptr = new WeakPtr<Object>(object);
    duk_push_pointer(ctx, ptr);
    duk_put_prop_string(ctx, -2, "\xff""weak");
    duk_push_c_function(ctx, WeakPtr_Finalizer, 1);
    duk_set_finalizer(ctx, -2);

    // Set prototype. If not found, use base class prototype (e.g. IComponent)
    duk_get_global_string(ctx, object->GetTypeName().CString());
    if (!duk_is_object(ctx, -1))
    {
        duk_pop(ctx);
        duk_get_global_string(ctx, object->GetTypeInfo()->GetBaseTypeInfo()->GetTypeName().CString());
    }
    duk_get_prop_string(ctx, -1, "prototype");
    duk_set_prototype(ctx, -3);
    duk_pop(ctx);

    // Proxied property access handling for scene, entity & component
    if (object->GetType() == Scene::GetTypeStatic())
        SetupProxy(ctx, SceneProxyFunctions);
    if (object->GetType() == Entity::GetTypeStatic())
        SetupProxy(ctx, EntityProxyFunctions);
    else if (dynamic_cast<IComponent*>(object))
        SetupProxy(ctx, ComponentProxyFunctions);

    // Store to stash
    duk_dup(ctx, -1);
    duk_put_prop_index(ctx, -3, (size_t)object);
    duk_remove(ctx, -2); // Remove stash
}
Example #4
0
void LuaScriptInstance::HandleEvent(StringHash eventType, VariantMap& eventData)
{
    WeakPtr<LuaFunction> function = eventTypeToFunctionMap_[eventType];
    if (function && function->BeginCall(this))
    {
        function->PushUserType(eventType, "StringHash");
        function->PushUserType(eventData, "VariantMap");
        function->EndCall();
    }
}
Example #5
0
void LuaScriptInstance::HandleObjectEvent(StringHash eventType, VariantMap& eventData)
{
    Object* object = GetEventSender();
    WeakPtr<LuaFunction> function = objectToEventTypeToFunctionMap_[object][eventType];
    if (function && function->BeginCall(this))
    {
        function->PushUserType(eventType, "StringHash");
        function->PushUserType(eventData, "VariantMap");
        function->EndCall();
    }
}
Example #6
0
void LuaScriptInstance::HandlePostFixedUpdate(StringHash eventType, VariantMap& eventData)
{
    using namespace PhysicsPostStep;
    float timeStep = eventData[P_TIMESTEP].GetFloat();

    WeakPtr<LuaFunction> function = scriptObjectMethods_[LSOM_FIXEDPOSTUPDATE];
    if (function && function->BeginCall(this))
    {
        function->PushFloat(timeStep);
        function->EndCall();
    }
}
RawPtr<Node> NodeIntersectionObserverData::createWeakPtr(Node* node)
{
#if ENABLE(OILPAN)
    return node;
#else
    if (!m_weakPointerFactory)
        m_weakPointerFactory = new WeakPtrFactory<Node>(node);
    WeakPtr<Node> result = m_weakPointerFactory->createWeakPtr();
    ASSERT(result.get() == node);
    return result;
#endif
}
Example #8
0
		/*=============================================================================
		-- Drops the object with the id in the inventory if it exists.
		=============================================================================*/
		void Actor::DropObject(int id)
		{
			//place the object on the ground behind the Actor so it does not walk over it right away.
			WeakPtr<Object> object = mInventory->GetObject(id);

			if (!object.expired())
			{
				object.lock()->SetHeld(false);
				object.lock()->SetPos(Vector3D<double>(GetPos().x+32.0, GetPos().y+32.0, GetPos().z+2.0));
				mInventory->RemoveObject(id);
			}
		}
Example #9
0
		/*=============================================================================
		-- Special actions for colliding with certain enity types.
		=============================================================================*/
		void Actor::ReactToCollision(WeakPtr<Entity> entity)
		{
			if (entity.expired())
				return;

			if (entity.lock()->GetType() == OBJECT)
			{
				WeakPtr<Object> object = WeakPtr<Object>(DynamicPtrCast<Object>(entity.lock()));

				if (object.lock()->GetObtainable())
					HoldObject( object );
			}
		}
Example #10
0
void LuaScriptInstance::SetScriptNetworkDataAttr(PODVector<unsigned char> data)
{
    if (scriptObjectRef_ == LUA_REFNIL)
        return;

    WeakPtr<LuaFunction> function = scriptObjectMethods_[LSOM_READNETWORKUPDATE];
    if (function && function->BeginCall(this))
    {
        MemoryBuffer buf(data);
        function->PushUserType((Deserializer&)buf, "Deserializer");
        function->EndCall();
    }
}
Example #11
0
void LuaScript::HandleEvent(StringHash eventType, VariantMap& eventData)
{
    LuaFunctionVector& functions = eventHandleFunctions_[eventType];
    for (unsigned i = 0; i < functions.Size(); ++i)
    {
        WeakPtr<LuaFunction> function = functions[i];
        if (function && function->BeginCall())
        {
            function->PushUserType(eventType, "StringHash");
            function->PushUserType(eventData, "VariantMap");
            function->EndCall();
        }
    }
}
Example #12
0
void GenericEventQueue::sharedTimerFired()
{
    ASSERT(!sharedTimer().isActive());
    ASSERT(!pendingQueues().isEmpty());

    while (!pendingQueues().isEmpty()) {
        WeakPtr<GenericEventQueue> queue = pendingQueues().takeFirst();
        if (!queue)
            continue;
        queue->dispatchOneEvent();
    }

    if (sharedTimer().isActive())
        sharedTimer().stop();
}
Example #13
0
    WeakPtr(const WeakPtr<S>& src)
    {
        if (src.isValid()) {
            ptr = src.getRawPtr();
#ifdef WEAK_PTR_HAS_EXTRA_PTR_TO_COUNTERS
            heapObjectCounters = HeapObjectRefManipulator::getHeapObjectCounters(ptr);
#endif
            HeapObjectRefManipulator::incWeakCounter(getHeapObjectCounters());
        } else {
            ptr = NULL;
#ifdef WEAK_PTR_HAS_EXTRA_PTR_TO_COUNTERS
            heapObjectCounters = NULL;
#endif
        }
    }
InProcessWorkerObjectProxy::InProcessWorkerObjectProxy(
    const WeakPtr<InProcessWorkerMessagingProxy>& messagingProxy)
    : m_messagingProxy(messagingProxy.get()),
      m_messagingProxyWeakPtr(messagingProxy),
      m_defaultIntervalInSec(kDefaultIntervalInSec),
      m_nextIntervalInSec(kDefaultIntervalInSec),
      m_maxIntervalInSec(kMaxIntervalInSec) {}
Example #15
0
void LuaScriptInstance::OnMarkedDirty(Node* node)
{
    // Script functions are not safe from worker threads
    Scene* scene = GetScene();
    if (scene && scene->IsThreadedUpdate())
    {
        scene->DelayedMarkedDirty(this);
        return;
    }

    WeakPtr<LuaFunction> function = scriptObjectMethods_[LSOM_TRANSFORMCHANGED];
    if (function && function->BeginCall(this))
    {
        function->EndCall();
    }
}
Example #16
0
PODVector<unsigned char> LuaScriptInstance::GetScriptNetworkDataAttr() const
{
    if (scriptObjectRef_ == LUA_REFNIL)
        return PODVector<unsigned char>();

    VectorBuffer buf;

    WeakPtr<LuaFunction> function = scriptObjectMethods_[LSOM_WRITENETWORKUPDATE];
    if (function && function->BeginCall(this))
    {
        function->PushUserType((Serializer&)buf, "Serializer");
        function->EndCall();
    }

    return buf.GetBuffer();
}
Example #17
0
SimpleReaderNode::Ptr SimpleReaderNode::create(const QString &name, WeakPtr parent)
{
    Ptr newNode(new SimpleReaderNode(name, parent));
    newNode->m_weakThis = newNode;
    if (parent)
        parent.data()->m_children.append(newNode);
    return newNode;
}
Example #18
0
    WeakPtr(const WeakPtr& src)
        : ptr(src.getRawPtr())
#ifdef WEAK_PTR_HAS_EXTRA_PTR_TO_COUNTERS
        , heapObjectCounters(HeapObjectRefManipulator::getHeapObjectCounters(ptr))
#endif
    {
        ASSERT(this != &src);
        HeapObjectRefManipulator::incWeakCounter(getHeapObjectCounters());
    }
Example #19
0
void LuaScriptInstance::ReleaseObject()
{
    if (scriptObjectRef_ == LUA_REFNIL)
        return;

    if (IsEnabledEffective())
        UnsubscribeFromScriptMethodEvents();

    // Unref script object
    luaL_unref(luaState_, LUA_REGISTRYINDEX, scriptObjectRef_);
    scriptObjectRef_ = LUA_REFNIL;

    WeakPtr<LuaFunction> function = luaScript_->GetFunction("DestroyScriptObjectInstance");
    if (function && function->BeginCall())
    {
        function->PushUserType((void*)this, "LuaScriptInstance");
        function->EndCall();
    }
}
Example #20
0
ImageDataCache::Ptr ImageDataCachePrivate::lookup(ImageDataMetadata::Ptr metadata)
{
    if (cache.contains(metadata)) {
        WeakPtr weakPtr = cache[metadata];
        ImageDataCache::Ptr ptr = weakPtr.toStrongRef();

        if (ptr.isNull()) {
            cache.remove(metadata);
        } else {
            return ptr;
        }
    }

    ImageDataCache::Ptr ptr(new ImageDataCache::CacheEntry());

    cache.insert(metadata, ptr.toWeakRef());

    return ptr;
}
Example #21
0
const SymbolPath SymbolNode::getSymPath() const
{
	SymbolPath path;
	const SymbolNode* curNode = this;
	for (WeakPtr wpParent = m_parent; !wpParent.isNull();)
	{
		Ptr pParent = wpParent.toStrongRef();
		for (ConstChildIterator pChild = pParent->childConstBegin();
			pChild != pParent->childConstEnd(); ++pChild)
		{
			if (pChild.value().data() == curNode)
			{
				path.addParentSymbol(pChild.key());
				break;
			}
		}
		wpParent = pParent->m_parent;
	}
	return path;
}
void UIDragDrop::DragEnd()
{
    SharedPtr<UIDragObject> dragObject = dragObject_;
    WeakPtr<UIWidget> currentTargetWidget = currentTargetWidget_;

    // clean up
    currentTargetWidget_ = 0;
    dragObject_ = 0;
    dragSourceWidget_ = 0;
    dragLayout_->SetVisibility(UI_WIDGET_VISIBILITY_GONE);

    if (currentTargetWidget.Null())
    {
        return;
    }

    VariantMap dropData;
    dropData[DragEnded::P_TARGET] = currentTargetWidget;
    dropData[DragEnded::P_DRAGOBJECT] = dragObject;
    currentTargetWidget->SendEvent(E_DRAGENDED, dropData);
}
Example #23
0
SharedPtr<OclDevice> OclDevice::getInstance()
{
    AutoLock lock(m_lock);
    SharedPtr<OclDevice> device = m_instance.lock();
    if (device)
        return device;
    device.reset(new OclDevice);
    if (!device->init()) {
        device.reset();
    }
    return device;
}
Example #24
0
void LuaScriptInstance::SetScriptObjectType(const String& scriptObjectType)
{
    if (scriptObjectType_ == scriptObjectType)
        return;

    ReleaseObject();

    WeakPtr<LuaFunction> function = luaScript_->GetFunction("CreateScriptObjectInstance");
    if (!function || !function->BeginCall())
        return;

    function->PushLuaTable(scriptObjectType);
    function->PushUserType((void*)this, "LuaScriptInstance");
    
    if (!function->EndCall(1))
        return;

    scriptObjectType_ = scriptObjectType;
    scriptObjectRef_ = luaL_ref(luaState_, LUA_REGISTRYINDEX);

    // Find script object method refs
    FindScriptObjectMethodRefs();
}
Example #25
0
void Vehicle::InitWheel(const String& name, const Vector3& offset, WeakPtr<Node>& wheelNode, unsigned& wheelNodeID)
{
    ResourceCache* cache = GetSubsystem<ResourceCache>();

    // Note: do not parent the wheel to the hull scene node. Instead create it on the root level and let the physics
    // constraint keep it together
    wheelNode = GetScene()->CreateChild(name);
    wheelNode->SetPosition(node_->LocalToWorld(offset));
    wheelNode->SetRotation(node_->GetRotation() * (offset.x_ >= 0.0 ? Quaternion(0.0f, 0.0f, -90.0f) :
        Quaternion(0.0f, 0.0f, 90.0f)));
    wheelNode->SetScale(Vector3(0.8f, 0.5f, 0.8f));
    // Remember the ID for serialization
    wheelNodeID = wheelNode->GetID();

    StaticModel* wheelObject = wheelNode->CreateComponent<StaticModel>();
    RigidBody* wheelBody = wheelNode->CreateComponent<RigidBody>();
    CollisionShape* wheelShape = wheelNode->CreateComponent<CollisionShape>();
    Constraint* wheelConstraint = wheelNode->CreateComponent<Constraint>();

    wheelObject->SetModel(cache->GetResource<Model>("Models/Cylinder.mdl"));
    wheelObject->SetMaterial(cache->GetResource<Material>("Materials/Stone.xml"));
    wheelObject->SetCastShadows(true);
    wheelShape->SetSphere(1.0f);
    wheelBody->SetFriction(1.0f);
    wheelBody->SetMass(1.0f);
    wheelBody->SetLinearDamping(0.2f); // Some air resistance
    wheelBody->SetAngularDamping(0.75f); // Could also use rolling friction
    wheelBody->SetCollisionLayer(1);
    wheelConstraint->SetConstraintType(CONSTRAINT_HINGE);
    wheelConstraint->SetOtherBody(GetComponent<RigidBody>()); // Connect to the hull body
    wheelConstraint->SetWorldPosition(wheelNode->GetPosition()); // Set constraint's both ends at wheel's location
    wheelConstraint->SetAxis(Vector3::UP); // Wheel rotates around its local Y-axis
    wheelConstraint->SetOtherAxis(offset.x_ >= 0.0 ? Vector3::RIGHT : Vector3::LEFT); // Wheel's hull axis points either left or right
    wheelConstraint->SetLowLimit(Vector2(-180.0f, 0.0f)); // Let the wheel rotate freely around the axis
    wheelConstraint->SetHighLimit(Vector2(180.0f, 0.0f));
    wheelConstraint->SetDisableCollision(true); // Let the wheel intersect the vehicle hull
}
Example #26
0
		Box::Box(WeakPtr<SweepBox> sweepBox)
		{
			_SetType(BOX);
			_SetId(sweepBox.lock()->GetId());
			_SetPos(sweepBox.lock()->GetPos());
			_SetSize(sweepBox.lock()->GetWidth(), sweepBox.lock()->GetLength(), sweepBox.lock()->GetHeight());
			_SetVelocity(sweepBox.lock()->GetVelocity());//TODO this is probably unecessary, so optimize out
			mSweepBox = SharedPtr<SweepBox>(new SweepBox);
		}
Example #27
0
		void ListBox::SelectCell(WeakPtr<Cell> cell)
		{
			//ensure the cell is actually a cell in the listbox
			std::vector< WeakPtr<Cell> >::iterator iter = mCells.begin();
			while (iter != mCells.end())
			{
				if ((*iter).lock() == cell.lock())
				{
					mSelectedCell = cell;
					_SendElementMessageToListeners(ElementEvent::SELECTED, mSelectedCell.lock()->GetUID());
					return;
				}

				iter++;
			}
		}
Example #28
0
void LuaScriptInstance::OnSetAttribute(const AttributeInfo& attr, const Variant& src)
{
    if (attr.ptr_ != (void*)0xffffffff)
    {
        Serializable::OnSetAttribute(attr, src);
        return;
    }

    if (scriptObjectRef_ == LUA_REFNIL)
        return;

    String name = attr.name_;
    unsigned length = name.Length();
    if (name.Back() == '_')
        length -= 1;

    int top = lua_gettop(luaState_);

    String functionName = String("Set") + name.Substring(0, 1).ToUpper() + name.Substring(1, length - 1);
    WeakPtr<LuaFunction> function = GetScriptObjectFunction(functionName);
    // If set function exist
    if (function)
    {
        if (function->BeginCall(this))
        {
            function->PushVariant(src);
            function->EndCall();
        }
    }
    else
    {
        lua_rawgeti(luaState_, LUA_REGISTRYINDEX, scriptObjectRef_);
        lua_pushstring(luaState_, name.CString());

        switch (attr.type_)
        {
        case VAR_BOOL:
            lua_pushboolean(luaState_, src.GetBool());
            break;
        case VAR_FLOAT:
            lua_pushnumber(luaState_, src.GetFloat());
            break;
        case VAR_STRING:
            tolua_pushurho3dstring(luaState_, src.GetString());
            break;
        case VAR_VECTOR2:
        {
            Vector2* value = new Vector2(src.GetVector2());
            tolua_pushusertype(luaState_, value, "Vector2");
            tolua_register_gc(luaState_, lua_gettop(luaState_));
        }
        break;
        case VAR_VECTOR3:
        {
            Vector3* value = new Vector3(src.GetVector3());
            tolua_pushusertype(luaState_, value, "Vector3");
            tolua_register_gc(luaState_, lua_gettop(luaState_));
        }
        break;
        case VAR_VECTOR4:
        {
            Vector4* value = new Vector4(src.GetVector4());
            tolua_pushusertype(luaState_, value, "Vector4");
            tolua_register_gc(luaState_, lua_gettop(luaState_));
        }
        break;
        case VAR_QUATERNION:
        {
            Quaternion* value = new Quaternion(src.GetQuaternion());
            tolua_pushusertype(luaState_, value, "Quaternion");
            tolua_register_gc(luaState_, lua_gettop(luaState_));
        }

        break;
        case VAR_COLOR:
        {
            Color* value = new Color(src.GetColor());
            tolua_pushusertype(luaState_, value, "Color");
            tolua_register_gc(luaState_, lua_gettop(luaState_));
        }
        break;
        case VAR_INTRECT:
        {
            IntRect* value = new IntRect(src.GetIntRect());
            tolua_pushusertype(luaState_, value, "IntRect");
            tolua_register_gc(luaState_, lua_gettop(luaState_));
        }
        break;
        case VAR_INTVECTOR2:
        {
            IntVector2* value = new IntVector2(src.GetIntVector2());
            tolua_pushusertype(luaState_, value, "IntVector2");
            tolua_register_gc(luaState_, lua_gettop(luaState_));
        }
        break;
        default:
            LOGERROR("Unsupported data type");
            lua_settop(luaState_, top);
            return;
        }

        lua_settable(luaState_, -3);
    }

    lua_settop(luaState_, top);
}
Example #29
0
void LuaIntegration::CreateScene()
{
    ResourceCache* cache = GetSubsystem<ResourceCache>();

    scene_ = new Scene(context_);

    // Create the Octree component to the scene so that drawable objects can be rendered. Use default volume
    // (-1000, -1000, -1000) to (1000, 1000, 1000)
    scene_->CreateComponent<Octree>();

    // Create a Zone component into a child scene node. The Zone controls ambient lighting and fog settings. Like the Octree,
    // it also defines its volume with a bounding box, but can be rotated (so it does not need to be aligned to the world X, Y
    // and Z axes.) Drawable objects "pick up" the zone they belong to and use it when rendering; several zones can exist
    Node* zoneNode = scene_->CreateChild("Zone");
    Zone* zone = zoneNode->CreateComponent<Zone>();
    // Set same volume as the Octree, set a close bluish fog and some ambient light
    zone->SetBoundingBox(BoundingBox(-1000.0f, 1000.0f));
    zone->SetAmbientColor(Color(0.05f, 0.1f, 0.15f));
    zone->SetFogColor(Color(0.1f, 0.2f, 0.3f));
    zone->SetFogStart(10.0f);
    zone->SetFogEnd(100.0f);
    
    LuaFile* scriptFile = cache->GetResource<LuaFile>("LuaScripts/Rotator.lua");
    if (!scriptFile)
        return;

    // Create randomly positioned and oriented box StaticModels in the scene
    const unsigned NUM_OBJECTS = 2000;
    for (unsigned i = 0; i < NUM_OBJECTS; ++i)
    {
        Node* boxNode = scene_->CreateChild("Box");
        boxNode->SetPosition(Vector3(Random(200.0f) - 100.0f, Random(200.0f) - 100.0f, Random(200.0f) - 100.0f));
        // Orient using random pitch, yaw and roll Euler angles
        boxNode->SetRotation(Quaternion(Random(360.0f), Random(360.0f), Random(360.0f)));
        StaticModel* boxObject = boxNode->CreateComponent<StaticModel>();
        boxObject->SetModel(cache->GetResource<Model>("Models/Box.mdl"));
        boxObject->SetMaterial(cache->GetResource<Material>("Materials/Stone.xml"));
        
        // Add our custom Rotator script object (using the LuaScriptInstance C++ component to instantiate / store it) which will
        // rotate the scene node each frame, when the scene sends its update event
        LuaScriptInstance* instance = boxNode->CreateComponent<LuaScriptInstance>();
        instance->CreateObject(scriptFile, "Rotator");
        
        // Call the script object's "SetRotationSpeed" function.
        WeakPtr<LuaFunction> function = instance->GetScriptObjectFunction("SetRotationSpeed");
        if (function && function->BeginCall(instance))
        {
            function->PushUserType(Vector3(10.0f, 20.0f, 30.0f), "Vector3");
            function->EndCall();
        }
    }
    
    // Create the camera. Let the starting position be at the world origin. As the fog limits maximum visible distance, we can
    // bring the far clip plane closer for more effective culling of distant objects
    cameraNode_ = scene_->CreateChild("Camera");
    Camera* camera = cameraNode_->CreateComponent<Camera>();
    camera->SetFarClip(100.0f);
    
    // Create a point light to the camera scene node
    Light* light = cameraNode_->CreateComponent<Light>();
    light->SetLightType(LIGHT_POINT);
    light->SetRange(30.0f);
}
Example #30
0
void LuaScriptInstance::OnGetAttribute(const AttributeInfo& attr, Variant& dest) const
{
    if (attr.ptr_ != (void*)0xffffffff)
    {
        Serializable::OnGetAttribute(attr, dest);
        return;
    }

    if (scriptObjectRef_ == LUA_REFNIL)
        return;

    String name = attr.name_;
    unsigned length = name.Length();
    if (name.Back() == '_')
        length -= 1;

    int top = lua_gettop(luaState_);

    String functionName = String("Get") + name.Substring(0, 1).ToUpper() + name.Substring(1, length - 1);
    WeakPtr<LuaFunction> function = GetScriptObjectFunction(functionName);
    // If get function exist
    if (function)
    {
        if (function->BeginCall(this))
            function->EndCall(1);
    }
    else
    {
        lua_rawgeti(luaState_, LUA_REGISTRYINDEX, scriptObjectRef_);
        lua_pushstring(luaState_, name.CString());
        lua_gettable(luaState_, -2);
    }

    switch (attr.type_)
    {
    case VAR_BOOL:
        dest = lua_toboolean(luaState_, -1) != 0;
        break;
    case VAR_FLOAT:
        dest = (float)lua_tonumber(luaState_, -1);
        break;
    case VAR_STRING:
        dest = tolua_tourho3dstring(luaState_, -1, "");
        break;
    case VAR_VECTOR2:
        dest = *((Vector2*)tolua_tousertype(luaState_, -1, 0));
        break;
    case VAR_VECTOR3:
        dest = *((Vector3*)tolua_tousertype(luaState_, -1, 0));
        break;
    case VAR_VECTOR4:
        dest = *((Vector4*)tolua_tousertype(luaState_, -1, 0));
        break;
    case VAR_QUATERNION:
        dest = *((Quaternion*)tolua_tousertype(luaState_, -1, 0));
        break;
    case VAR_COLOR:
        dest = *((Color*)tolua_tousertype(luaState_, -1, 0));
        break;
    case VAR_INTRECT:
        dest = *((IntRect*)tolua_tousertype(luaState_, -1, 0));
        break;
    case VAR_INTVECTOR2:
        dest = *((IntVector2*)tolua_tousertype(luaState_, -1, 0));
        break;
    default:
        LOGERROR("Unsupported data type");
        return;
    }

    lua_settop(luaState_, top);
}