示例#1
0
template <> int ToluaPushVector<String>(lua_State* L, void* data, const char* /*type*/)
{
    lua_newtable(L);
    const Vector<String>& vector = *static_cast<const Vector<String>*>(data);
    for (unsigned i = 0; i < vector.Size(); ++i)
    {
        tolua_pushurho3dstring(L, vector[i]);
        lua_rawseti(L, -2, i + 1);
    }
    return 1;
}
示例#2
0
template<> int ToluaPushVector<String>(lua_State* L, void* data, const char* type)
{
    const Vector<String>& vectorstring = *((const Vector<String>*)data);
    lua_newtable(L);
    for (unsigned i = 0; i < vectorstring.Size(); ++i)
    {
        tolua_pushurho3dstring(L, vectorstring[i]);
        lua_rawseti(L, -2, i + 1);
    }
    return 1;
}
示例#3
0
void LuaFunction::PushString(const String& string)
{
    assert(numArguments_ >= 0);
    ++numArguments_;
    tolua_pushurho3dstring(luaState_, string);
}
示例#4
0
void ToluaPushVariant(lua_State* L, const Variant* variant, const char* type)
{
    String typeName(type);
    switch (variant->GetType())
    {
    case VAR_INT:
        if (typeName == "unsigned" || typeName == "unsigned int" || typeName == "UInt" || typeName == "uint")
            tolua_pushnumber(L, (lua_Number)variant->GetUInt());
        else if (typeName == "StringHash")
        {
            // Make a new local copy
            tolua_pushusertype(L, Mtolua_new(StringHash(variant->GetStringHash())), "StringHash");
            tolua_register_gc(L, lua_gettop(L));
        }
        else
            tolua_pushnumber(L, (lua_Number)variant->GetInt());
        break;

    case VAR_BOOL:
        tolua_pushboolean(L, (int)variant->GetBool());
        break;

    case VAR_FLOAT:
        tolua_pushnumber(L, (lua_Number)variant->GetFloat());
        break;

    case VAR_DOUBLE:
        tolua_pushnumber(L, (lua_Number)variant->GetDouble());
        break;

    case VAR_VECTOR2:
    case VAR_VECTOR3:
    case VAR_VECTOR4:
    case VAR_QUATERNION:
    case VAR_COLOR:
    case VAR_RESOURCEREF:
    case VAR_RESOURCEREFLIST:
    case VAR_VARIANTMAP:
    case VAR_INTRECT:
    case VAR_INTVECTOR2:
        tolua_pushusertype(L, (void*)variant->Get<const VariantValue*>(), variant->GetTypeName().CString());
        break;

    case VAR_STRING:
        tolua_pushurho3dstring(L, variant->GetString());
        break;

    case VAR_BUFFER:
        if (typeName == "VectorBuffer")
        {
            tolua_pushusertype(L, Mtolua_new(VectorBuffer(variant->GetVectorBuffer())), "VectorBuffer");
            tolua_register_gc(L, lua_gettop(L));
        }
        else
            ToluaPushPODVector<unsigned char>(0.f, L, (void*)&variant->GetBuffer(), "unsigned char");
        break;

    case VAR_VOIDPTR:
        ToluaPushRegisteredUserType(L, static_cast<void*>(variant->GetVoidPtr()), type);
        break;

    case VAR_PTR:
        ToluaPushRegisteredUserType(L, static_cast<void*>(variant->GetPtr()), type);
        break;

    case VAR_VARIANTVECTOR:
        ToluaPushVector<Variant>(L, (void*)&variant->GetVariantVector(), "Variant");
        break;

    case VAR_STRINGVECTOR:
        ToluaPushVector<String>(L, (void*)&variant->GetStringVector(), "String");
        break;

    case VAR_MATRIX3:
    case VAR_MATRIX3X4:
    case VAR_MATRIX4:
        tolua_pushusertype(L, variant->Get<const VariantValue*>()->ptr_, variant->GetTypeName().CString());
        break;

    default:
        lua_pushnil(L);
        break;
    }
}