qcode
  • 创作工场专业版,一问多答!更智能、更完整、更原创
  • 这是一个超强内容创作平台,它会写文章、做设计、绘图、敲代码,有问必答!
🔥点击使用-高级专业版🔥

static int ForEachMob(lua_State* L) {

时间2023-04-01 00:32:04 提问来自 上海市上海市 的网友 分类创作 浏览308
int n = lua_gettop(L); if (n != 2) { luaL_error(L, "ForEachMob requires 2 arguments, %d given.", n); } auto scope = GetLuaObject<Scope>(L, 1); if (!scope) { return luaL_error(L, "ForEachMob argument 1 must be a Scope."); } auto func = GetLuaFunctionRef(L, 2); auto &mobs = scope->GetMobs(); for (auto it : mobs) { // iterate through mobs in this scope. // Push the function reference onto the stack and call it. The callback should take one parameter - mob. lua_rawgeti(L, LUA_REGISTRYINDEX, func); // Push the function onto the stack. SetLuaObject<Mob>(L, it.second); // Push mob onto the stack as an argument to the function call. if (lua_pcall(L, 1 /*num args*/ , 0 /*num return values*/ , 0 /*errfunc*/ ) != 0) { // Call our callback with one parameter - mob and no return values expected. const char *errmsg = lua_tostring ( L , -1 ); // get error message from top of stack (-1). This pops off the error message from the stack so that when we leave this function our stack is back to normal with no extra stuff on it. printf("Error running ForEachMob: %s\n", errmsg ); // print out error message for debugging purposes only... not for user display! This is because most errors will be typos in your script code which you need to see on your screen so you can fix them! :-) return 0; // Return failure since there was an error running our callback code! Note that we don't need to pop off any extra stuff from our Lua Stack since Lua will handle cleaning up whatever is left on its own internal Stack when this C++ function returns back to Lua land! :-) } } return 0; // Return success since we finished looping through all mobs without any errors! :-) Note that we don't need to pop off any extra stuff from our Lua Stack since Lua will handle cleaning up whatever is left on its own internal Stack when this C++ function returns back to Lua land! :-) Yay!!! :-D Hooray!!! \o/ \o/ \o/ Let's Party!!! :-P LOL!!! ;-) *whew* That was close!! Phew!! I almost forgot about popping something off my C++ Stack before returning!! LOL!!!! ;-) Whew!! Close call there!! lol!!!! :-P Anyways.... moving right along.... ;-) Yay!!!! \o/ \o/ \o/ Hooray!!! Let's Party!!!!! w00t w00t w00t!!!!!!!!! :-D Rock On Dudez!!!!! 8-) Peace Out Homiez!!!! 8-) <---- See how easy it is for me to get sidetracked?? lol!!! ;-) Anyways..... yeah.... moving right along..... ;-) Back To Work We Go!!!!! lol!!!! 8-) */ }

点击这里,进行内容创作

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

上一篇 写一首歌唱湖南美景的歌 下一篇 通过以上探索,你认为自己在检测技术与仪器专业(包括心仪专业)有可能的职业去向有哪些?请列出2~5个职业(含行业/职业/岗位)