bool ScriptApiItem::item_OnDrop(ItemStack &item, ServerActiveObject *dropper, v3f pos) { SCRIPTAPI_PRECHECKHEADER int error_handler = PUSH_ERROR_HANDLER(L); // Push callback function on stack if (!getItemCallback(item.name.c_str(), "on_drop")) return false; // Call function LuaItemStack::create(L, item); objectrefGetOrCreate(L, dropper); pushFloatPos(L, pos); PCALL_RES(lua_pcall(L, 3, 1, error_handler)); if (!lua_isnil(L, -1)) { try { item = read_item(L,-1, getServer()); } catch (LuaError &e) { throw LuaError(std::string(e.what()) + ". item=" + item.name); } } lua_pop(L, 2); // Pop item and error handler return true; }
// get_acceleration(self) int ObjectRef::l_get_acceleration(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); if (co == NULL) return 0; // Do it v3f v = co->getAcceleration(); pushFloatPos(L, v); return 1; }
// getvelocity(self) int ObjectRef::l_getvelocity(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); { PlayerSAO* co = getplayersao(ref); if (co) { v3f v = co->getPlayer()->getSpeed(); pushFloatPos(L, v); return 1; } } LuaEntitySAO *co = getluaobject(ref); if (co == NULL) return 0; // Do it v3f v = co->getVelocity(); pushFloatPos(L, v); return 1; }
bool scriptapi_item_on_drop(lua_State *L, ItemStack &item, ServerActiveObject *dropper, v3f pos) { realitycheck(L); assert(lua_checkstack(L, 20)); StackUnroller stack_unroller(L); // Push callback function on stack if(!get_item_callback(L, item.name.c_str(), "on_drop")) return false; // Call function LuaItemStack::create(L, item); objectref_get_or_create(L, dropper); pushFloatPos(L, pos); if(lua_pcall(L, 3, 1, 0)) script_error(L, "error: %s", lua_tostring(L, -1)); if(!lua_isnil(L, -1)) item = read_item(L, -1); return true; }
bool ScriptApiItem::item_OnDrop(ItemStack &item, ServerActiveObject *dropper, v3f pos) { SCRIPTAPI_PRECHECKHEADER lua_pushcfunction(L, script_error_handler); int errorhandler = lua_gettop(L); // Push callback function on stack if(!getItemCallback(item.name.c_str(), "on_drop")) return false; // Call function LuaItemStack::create(L, item); objectrefGetOrCreate(dropper); pushFloatPos(L, pos); if(lua_pcall(L, 3, 1, errorhandler)) scriptError(); if(!lua_isnil(L, -1)) item = read_item(L,-1, getServer()); lua_pop(L, 2); // Pop item and error handler return true; }