aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_env.cpp
Commit message (Expand)AuthorAge
* Fix some reference counters (memleak) (#8981)SmallJoker2019-09-24
* Merge pull request #8776 from osjc/FixGetNodeJozef Behran2019-08-10
* Add minetest.load_area (#8023)HybridDog2018-12-31
* Move client-specific files to 'src/client' (#7902)Quentin Bazin2018-11-28
* Raycast: export exact pointing location (#6304)Dániel Juhász2018-08-16
* Modernize lua read (part 2 & 3): C++ templating assurance (#7410)Loïc Blot2018-06-30
* Rename CSM flavours to restrictionsSmallJoker2018-06-26
* Modernize lua read (part 1): C++ templating insurance (#7394)Loïc Blot2018-06-04
* Find nodes in area (under air): Raise volume limit and document itparamat2018-02-21
* Node definition manager refactor (#7016)Dániel Juhász2018-02-10
* Add minetest.bulk_set_node call + optimize Environment::set_node call (#6958)Loïc Blot2018-01-30
* Line_of_sight: Improve using VoxelLineIteratorDániel Juhász2017-12-26
* Clearobjects: Send progress messages to terminal using actionstreamparamat2017-11-24
* Move files to subdirectories (#6599)Vitaliy2017-11-08
* Set placer to nil instead of a non-functional one in item_OnPlace (#6449)DTA72017-09-21
* ServerEnv: Clean up object lifecycle handling (#6414)sfan52017-09-15
* Make INodeDefManager::getIds return a vector, not a setKahrl2017-09-12
* core.get_objects_inside_radius: Omit removed objects (#6318)you2017-08-27
* Modernize source code: last part (#6285)Loïc Blot2017-08-20
* Code modernization: subfolders (#6283)Loïc Blot2017-08-19
* Optimize headers (part 2) (#6272)Loïc Blot2017-08-18
* Cleanup various headers to reduce compilation times (#6255)Loïc Blot2017-08-16
* [CSM] Add flavour limits controlled by server (#5930)Loïc Blot2017-07-18
* Expose getPointedThing to LuaDániel Juhász2017-07-07
* find_nodes_in_area: Extend maximal count to U32_MAX (#5277)SmallJoker2017-06-19
* Clean up numeric.h and split FacePositionCache from itShadowNinja2017-05-06
* Add option to also check the center to `find_node_near` (#5255)red-0012017-05-04
* Rename Scripting API files for consistencyShadowNinja2017-04-25
* Fix various points reported by cppcheck (#5656)Loïc Blot2017-04-25
* Light update for map blocksDániel Juhász2017-04-20
* [CSM] Add core.get_timeofday & core.get_day_count env calls (#5401)Loïc Blot2017-03-17
* Add `get_wielded_item`red-0012017-03-13
* [CSM] Client side moddingLoic Blot2017-03-13
* Add ItemStack key-value meta storagerubenwardy2017-02-04
* Add staticdata parameter to add_entity (#5009)Rui2017-01-09
* Emergeblocks: Fix occasional crashRogier2016-10-16
* Player/LocalPlayer/RemotePlayer inheritance cleanup (part 1 on X)Loic Blot2016-10-08
* Change internal type for seeds to s32kwolekr2016-06-04
* Pathfinder: Fix styleest312016-05-01
* Add consistent monotonic day counter - get_day_count()Auke Kok2016-03-09
* Add minetest.register_lbm() to run code on block load onlyest312016-03-07
* Add '/clearobjects quick'Kahrl2016-02-11
* Add callback parameter for core.emerge_area()kwolekr2015-11-02
* SAPI: Move core.get_us_time() to Util modulekwolekr2015-10-26
* SAPI: Mark all Lua API functions requiring envlockkwolekr2015-10-25
* Add /emergeblocks command and core.emerge_area() Lua APIkwolekr2015-09-23
* Push error handler afresh each time lua_pcall is usedKahrl2015-08-27
* SEnv: Remove static_exists from ActiveObjects in deleted blockskwolekr2015-08-16
* SAPI: Track last executed mod and include in error messageskwolekr2015-08-12
* Improve Script CPP API diagnosticskwolekr2015-08-05
n class="hl kwc">std::string &name, const std::string &listname, int index, ItemStack &stack, ServerActiveObject *player) { SCRIPTAPI_PRECHECKHEADER int error_handler = PUSH_ERROR_HANDLER(L); // Push callback function on stack if (!getDetachedInventoryCallback(name, "allow_put")) return stack.count; // All will be accepted // Call function(inv, listname, index, stack, player) InventoryLocation loc; loc.setDetached(name); InvRef::create(L, loc); // inv lua_pushstring(L, listname.c_str()); // listname lua_pushinteger(L, index + 1); // index LuaItemStack::create(L, stack); // stack objectrefGetOrCreate(L, player); // player PCALL_RES(lua_pcall(L, 5, 1, error_handler)); if (!lua_isnumber(L, -1)) throw LuaError("allow_put should return a number. name=" + name); int ret = luaL_checkinteger(L, -1); lua_pop(L, 2); // Pop integer and error handler return ret; } // Return number of accepted items to be taken int ScriptApiDetached::detached_inventory_AllowTake( const std::string &name, const std::string &listname, int index, ItemStack &stack, ServerActiveObject *player) { SCRIPTAPI_PRECHECKHEADER int error_handler = PUSH_ERROR_HANDLER(L); // Push callback function on stack if (!getDetachedInventoryCallback(name, "allow_take")) return stack.count; // All will be accepted // Call function(inv, listname, index, stack, player) InventoryLocation loc; loc.setDetached(name); InvRef::create(L, loc); // inv lua_pushstring(L, listname.c_str()); // listname lua_pushinteger(L, index + 1); // index LuaItemStack::create(L, stack); // stack objectrefGetOrCreate(L, player); // player PCALL_RES(lua_pcall(L, 5, 1, error_handler)); if (!lua_isnumber(L, -1)) throw LuaError("allow_take should return a number. name=" + name); int ret = luaL_checkinteger(L, -1); lua_pop(L, 2); // Pop integer and error handler return ret; } // Report moved items void ScriptApiDetached::detached_inventory_OnMove( const std::string &name, const std::string &from_list, int from_index, const std::string &to_list, int to_index, int count, ServerActiveObject *player) { SCRIPTAPI_PRECHECKHEADER int error_handler = PUSH_ERROR_HANDLER(L); // Push callback function on stack if (!getDetachedInventoryCallback(name, "on_move")) return; // function(inv, from_list, from_index, to_list, to_index, count, player) // inv InventoryLocation loc; loc.setDetached(name); InvRef::create(L, loc); lua_pushstring(L, from_list.c_str()); // from_list lua_pushinteger(L, from_index + 1); // from_index lua_pushstring(L, to_list.c_str()); // to_list lua_pushinteger(L, to_index + 1); // to_index lua_pushinteger(L, count); // count objectrefGetOrCreate(L, player); // player PCALL_RES(lua_pcall(L, 7, 0, error_handler)); lua_pop(L, 1); // Pop error handler } // Report put items void ScriptApiDetached::detached_inventory_OnPut( const std::string &name, const std::string &listname, int index, ItemStack &stack, ServerActiveObject *player) { SCRIPTAPI_PRECHECKHEADER int error_handler = PUSH_ERROR_HANDLER(L); // Push callback function on stack if (!getDetachedInventoryCallback(name, "on_put")) return; // Call function(inv, listname, index, stack, player) // inv InventoryLocation loc; loc.setDetached(name); InvRef::create(L, loc); lua_pushstring(L, listname.c_str()); // listname lua_pushinteger(L, index + 1); // index LuaItemStack::create(L, stack); // stack objectrefGetOrCreate(L, player); // player PCALL_RES(lua_pcall(L, 5, 0, error_handler)); lua_pop(L, 1); // Pop error handler } // Report taken items void ScriptApiDetached::detached_inventory_OnTake( const std::string &name, const std::string &listname, int index, ItemStack &stack, ServerActiveObject *player) { SCRIPTAPI_PRECHECKHEADER int error_handler = PUSH_ERROR_HANDLER(L); // Push callback function on stack if (!getDetachedInventoryCallback(name, "on_take")) return; // Call function(inv, listname, index, stack, player) // inv InventoryLocation loc; loc.setDetached(name); InvRef::create(L, loc); lua_pushstring(L, listname.c_str()); // listname lua_pushinteger(L, index + 1); // index LuaItemStack::create(L, stack); // stack objectrefGetOrCreate(L, player); // player PCALL_RES(lua_pcall(L, 5, 0, error_handler)); lua_pop(L, 1); // Pop error handler } // Retrieves core.detached_inventories[name][callbackname] // If that is nil or on error, return false and stack is unchanged // If that is a function, returns true and pushes the // function onto the stack bool ScriptApiDetached::getDetachedInventoryCallback( const std::string &name, const char *callbackname) { lua_State *L = getStack(); lua_getglobal(L, "core"); lua_getfield(L, -1, "detached_inventories"); lua_remove(L, -2); luaL_checktype(L, -1, LUA_TTABLE); lua_getfield(L, -1, name.c_str()); lua_remove(L, -2); // Should be a table if(lua_type(L, -1) != LUA_TTABLE) { errorstream<<"Detached inventory \""<<name<<"\" not defined"<<std::endl; lua_pop(L, 1); return false; } setOriginFromTable(-1); lua_getfield(L, -1, callbackname); lua_remove(L, -2); // Should be a function or nil if(lua_type(L, -1) == LUA_TFUNCTION) { return true; } else if(lua_isnil(L, -1)) { lua_pop(L, 1); return false; } else { errorstream<<"Detached inventory \""<<name<<"\" callback \"" <<callbackname<<"\" is not a function"<<std::endl; lua_pop(L, 1); return false; } }