• “黑神话·悟空”免安装在线玩,无视显卡等硬件要求!!
  • √ 游戏免下载安装 √ 5分钟随开随玩 √ 关机不计费!低至¥14.90/月!
🔥进入竞技-直面天命🔥

static int ForEachMob(lua_State* L) {

时间2023-03-22 23:46:45 提问来自 上海市上海市 的网友 分类创作 浏览366
lua_pushnil(L); while (lua_next(L, -2) != 0) { if (!lua_isuserdata(L, -1)) { continue; } Mob* mob = static_cast<Mob*>(lua_touserdata(L, -1)); if (mob == nullptr || !mob->IsNPC()) { lua_pop(L, 1); continue; } if (ForEachMobFilter(L, mob)) { //pass the filter check? call the callback with this npc as an argument. If the callback returns false, break out of loop early. lua_pushvalue(L, -2); //copy key so lua_next will still work after callback is called. lua_pushvalue(L, 3); //callback function to be called. should be at index 3 of the stack now. lua_pushvalue(L, -3); //copy userdata so it will be at top of stack when callback is called. if (EQLua::CallStackFunction(nullptr, 2)) { //call the function with 2 arguments: key and userdata for npc we're looping over now. return value should be a boolean indicating whether or not to break out of loop early or not. bool result = false;//default to false in case something weird happens and we don't get a boolean back from CallStackFunction() for some reason. EQLua::PopBooleanFromStack(&result);//pop boolean from stack and store it in result variable for later use below in 'if' statement.. if (!result) {//did our callback return false? then break out of loop early! :D Otherwise keep going through NPC list normally.. break;//break out of while loop early since our callback returned false! :D This breaks us out of while() loop but leaves us with original table at top of stack still so we can do a 'return true' down below after while() loop ends.. yay! :D ..whew what a mouthful.. xP lololololol!! ^-^;;; heheheh... yeah... xP *ahem* moving on.... >_>;;; lolz.... xP I'm done rambling now... xP lolz.... ^-^;;;; heheh..... ;p *coughs* ok ok I'm done now I swear!!! >_>;; lolz..... xP ..anyway.... moving on.... >_>;; *ahem* yeah..... ;p next line please!! ^-^;;;; heheh..... ;p ok here it is: return true;//return true since our ForEachMobFilter() passed and our Callback returned false indicating that we should break out of while() loop early! :D yay success!! ^o^v \o/ \o/ \o/ \o/ w00t w00t!!! XD lolz.....xP .....now that's what I call an epic victory!! XD ....or something like that anyway..xP ....yeah...... ;p ....ok moving on again...... >_>;; ....weeeeeeee!!!! o/~ o/~ o/~ .....yeah.......xP ......ok next line please!! ^-^;;;; ......uhhhhhhh...... ;p ........ok here it is: ...............yes??................. ..................oh right next line: .........................ok here ya go: lua_pop(L ,1);//pop off npc userdata since we're done with it now and move on to next npc in list! :D yay success again!! XD .....now that's more like it!!! o/~ o/~ o/~ ...weeeeeeee!!!! XDDDDDDDDDD!!!!! ...lolz xP ...alrighty then moving on yet again..... >_>;; ......uhhhhhhhh.............. ;p ..........ok here ya goooooooooooooooo!!!!!!!!!!!!! .................yes???................................. ......................oh right next line!!!!!!!!!!!! } else {//our Callback didn't return false so just pop off copy of key and keep going through list normally.. lua_pop

点击这里,进行内容创作

创作工场 免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。
点击这里>>使用🔥专业版,更聪明、更完整、更原创!

上一篇 奥特曼和关羽对打(3张) 下一篇 当代青年能为国家统一、民族复兴做些什么?800字大学生论文