(转)LuaPlus子表遍历

本文介绍了一个使用Lua进行游戏对象配置的例子。通过解析Lua脚本中的表格数据,实现了游戏角色的模型、显示名称、缩放比例及特效等信息的加载。文章详细展示了如何遍历这些表格并打印出关键信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

简单的配置,先将就用吧,luaplus那由于别人的教材在表循环那里没写清楚,导致浪费了很多时间,最后还是看src才知道。

------------------------------------------------------------------------------------------------------

tabObjectData = {
[0x00001000] = {
   MeshName = "00040_lian.mesh",
   MeshDIR = "/models/Player/female/",
   ShowName = "女主角1",
   Scale = 0.01,
   Image = "ptgw.tga",
   ImageIndex = 0,
   EffectList = {
    [0x00000001] = {
     BindBone = "",
     OffestPos = { x = 0.0, y = 0.0, z= 0.0 },
     Direction = { x = 0.0, y = 0.0, z= 0.0 }
    }
   }
},
[0x00002000] = {
   MeshName = "男衣服30.mesh",
   MeshDIR = "/models/Player/male/",
   ShowName = "女主角1",
   Scale = 0.01,
   Image = "ptgw.tga",
   ImageIndex = 0,
   EffectList = {
    [0x00000001] = {
     BindBone = "",
     OffestPos = { x = 0.0, y = 0.0, z= 0.0 },
     Direction = { x = 0.0, y = 0.0, z= 0.0 }
    }
   }
},
[0x00000007] = {
   MeshName = "ninja.mesh",
   MeshDIR = "/models/Player/ninja/s",
   ShowName = "女主角1",
   Scale = 0.01,
   Image = "ptgw.tga",
   ImageIndex = 0,
   EffectList = {
    [0x00000001] = {
     BindBone = "",
     OffestPos = { x = 0.0, y = 0.0, z= 0.0 },
     Direction = { x = 0.0, y = 0.0, z= 0.0 }
    }
   }
}
}

--------------------------------------------------------------------------------------

LuaPlus::LuaObject ObjectData = GameGlobalManager::GetSingletonPtr()->getLuaState().Get()->GetGlobal( "tabObjectData" );
for ( LuaTableIterator it( ObjectData ); it; it++ )
{
   LuaPlus::LuaObject gameObj = it.GetValue();
   if ( gameObj.IsTable() )
   {
    //每个对象的表了
    printf( "对象:%08x\n", it.GetKey().ToInteger() );
   
    LuaPlus::LuaObject EffectObj = gameObj.GetByName( "EffectList" );
    if ( EffectObj.IsTable() )
    {
     for ( LuaTableIterator itr( EffectObj ); itr; itr++ )
     {
      if ( itr.GetValue().IsTable() )
      {
       printf( "对象:%08x的特效:%08x\n", it.GetKey().ToInteger(), itr.GetKey().ToInteger() );
      }
     }
    }    
   }   
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值