summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2015-04-23 22:20:31 +0200
committerMattes D <github@xoft.cz>2015-04-23 22:20:31 +0200
commita89d5f53fd51d4f7c95e6f32a3b1222f23a9cc35 (patch)
tree79efad21cec681afa82487a7a8a8fe39320ebbf0
parentDigging up a clay block spawns 4 clay items. (diff)
downloadcuberite-a89d5f53fd51d4f7c95e6f32a3b1222f23a9cc35.tar
cuberite-a89d5f53fd51d4f7c95e6f32a3b1222f23a9cc35.tar.gz
cuberite-a89d5f53fd51d4f7c95e6f32a3b1222f23a9cc35.tar.bz2
cuberite-a89d5f53fd51d4f7c95e6f32a3b1222f23a9cc35.tar.lz
cuberite-a89d5f53fd51d4f7c95e6f32a3b1222f23a9cc35.tar.xz
cuberite-a89d5f53fd51d4f7c95e6f32a3b1222f23a9cc35.tar.zst
cuberite-a89d5f53fd51d4f7c95e6f32a3b1222f23a9cc35.zip
Diffstat (limited to '')
-rw-r--r--MCServer/Plugins/APIDump/APIDesc.lua52
-rw-r--r--MCServer/Plugins/Debuggers/Debuggers.lua2
-rw-r--r--src/Bindings/LuaState.cpp18
-rw-r--r--src/Bindings/LuaState.h3
-rw-r--r--src/Bindings/ManualBindings.cpp603
5 files changed, 286 insertions, 392 deletions
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index 2224c549d..a3695fe17 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -1649,7 +1649,7 @@ a_Player:OpenWindow(Window);
]],
Functions =
{
- DoWithMap = { Params = "ID, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If a map with the specified ID exists, calls the CallbackFunction for that map. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cMap|Map}}, [CallbackData])</pre> Returns true if the map was found and the callback called, false if map not found." },
+ DoWithMap = { Params = "ID, CallbackFunction", Return = "bool", Notes = "If a map with the specified ID exists, calls the CallbackFunction for that map. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cMap|Map}})</pre> Returns true if the map was found and the callback called, false if map not found." },
GetNumMaps = { Params = "", Return = "number", Notes = "Returns the number of registered maps." },
},
@@ -2013,7 +2013,7 @@ a_Player:OpenWindow(Window);
BroadcastChatWarning = { Params = "MessageText", Return = "", Notes = "Broadcasts the specified message to all players, with its message type set to mtWarning. Use for concerning events, such as plugin reload etc." },
CreateAndInitializeWorld = { Params = "WorldName", Return = "{{cWorld|cWorld}}", Notes = "Creates a new world and initializes it. If there is a world whith the same name it returns nil.<br/><br/><b>NOTE</b>This function is currently unsafe, do not use!" },
FindAndDoWithPlayer = { Params = "PlayerName, CallbackFunction", Return = "", Notes = "Calls the given callback function for all players with names partially (or fully) matching the name string provided." },
- DoWithPlayerByUUID = { Params = "PlayerUUID, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is the player with the uuid, calls the CallbackFunction with the {{cPlayer}} parameter representing the player. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cPlayer|Player}}, [CallbackData])</pre> The function returns false if the player was not found, or whatever bool value the callback returned if the player was found." },
+ DoWithPlayerByUUID = { Params = "PlayerUUID, CallbackFunction", Return = "bool", Notes = "If there is the player with the uuid, calls the CallbackFunction with the {{cPlayer}} parameter representing the player. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cPlayer|Player}})</pre> The function returns false if the player was not found, or whatever bool value the callback returned if the player was found." },
ForEachPlayer = { Params = "CallbackFunction", Return = "", Notes = "Calls the given callback function for each player. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cPlayer|cPlayer}})</pre>" },
ForEachWorld = { Params = "CallbackFunction", Return = "", Notes = "Calls the given callback function for each world. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cWorld|cWorld}})</pre>" },
Get = { Params = "", Return = "Root object", Notes = "(STATIC)This function returns the cRoot object." },
@@ -2069,8 +2069,8 @@ end
Functions =
{
AddPlayerScore = { Params = "Name, Type, Value", Return = "", Notes = "Adds a value to all player scores of the specified objective type." },
- ForEachObjective = { Params = "CallBackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each objective in the scoreboard. Returns true if all objectives have been processed (including when there are zero objectives), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cObjective|Objective}}, [CallbackData])</pre> The callback should return false or no value to continue with the next objective, or true to abort the enumeration." },
- ForEachTeam = { Params = "CallBackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each team in the scoreboard. Returns true if all teams have been processed (including when there are zero teams), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cObjective|Objective}}, [CallbackData])</pre> The callback should return false or no value to continue with the next team, or true to abort the enumeration." },
+ ForEachObjective = { Params = "CallBackFunction", Return = "bool", Notes = "Calls the specified callback for each objective in the scoreboard. Returns true if all objectives have been processed (including when there are zero objectives), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cObjective|Objective}})</pre> The callback should return false or no value to continue with the next objective, or true to abort the enumeration." },
+ ForEachTeam = { Params = "CallBackFunction", Return = "bool", Notes = "Calls the specified callback for each team in the scoreboard. Returns true if all teams have been processed (including when there are zero teams), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cObjective|Objective}})</pre> The callback should return false or no value to continue with the next team, or true to abort the enumeration." },
GetNumObjectives = { Params = "", Return = "number", Notes = "Returns the nuber of registered objectives." },
GetNumTeams = { Params = "", Return = "number", Notes = "Returns the number of registered teams." },
GetObjective = { Params = "string", Return = "{{cObjective}}", Notes = "Returns the objective with the specified name." },
@@ -2277,33 +2277,33 @@ local CompressedString = cStringCompression.CompressStringGZIP("DataToCompress")
CreateProjectile = { Params = "X, Y, Z, {{cProjectileEntity|ProjectileKind}}, {{cEntity|Creator}}, {{cItem|Originating Item}}, [{{Vector3d|Speed}}]", Return = "", Notes = "Creates a new projectile of the specified kind at the specified coords. The projectile's creator is set to Creator (may be nil). The item that created the projectile entity, commonly the {{cPlayer|player}}'s currently equipped item, is used at present for fireworks to correctly set their entity metadata. It is not used for any other projectile. Optional speed indicates the initial speed for the projectile." },
DigBlock = { Params = "X, Y, Z", Return = "", Notes = "Replaces the specified block with air, without dropping the usual pickups for the block. Wakes up the simulators for the block and its neighbors." },
DoExplosionAt = { Params = "Force, X, Y, Z, CanCauseFire, Source, SourceData", Return = "", Notes = "Creates an explosion of the specified relative force in the specified position. If CanCauseFire is set, the explosion will set blocks on fire, too. The Source parameter specifies the source of the explosion, one of the esXXX constants. The SourceData parameter is specific to each source type, usually it provides more info about the source." },
- DoWithBlockEntityAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a block entity at the specified coords, calls the CallbackFunction with the {{cBlockEntity}} parameter representing the block entity. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cBlockEntity|BlockEntity}}, [CallbackData])</pre> The function returns false if there is no block entity, or if there is, it returns the bool value that the callback has returned. Use {{tolua}}.cast() to cast the Callback's BlockEntity parameter to the correct {{cBlockEntity}} descendant." },
- DoWithBeaconAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a beacon at the specified coords, calls the CallbackFunction with the {{cBeaconEntity}} parameter representing the beacon. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cBeaconEntity|BeaconEntity}}, [CallbackData])</pre> The function returns false if there is no beacon, or if there is, it returns the bool value that the callback has returned." },
- DoWithChestAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a chest at the specified coords, calls the CallbackFunction with the {{cChestEntity}} parameter representing the chest. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cChestEntity|ChestEntity}}, [CallbackData])</pre> The function returns false if there is no chest, or if there is, it returns the bool value that the callback has returned." },
- DoWithCommandBlockAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a command block at the specified coords, calls the CallbackFunction with the {{cCommandBlockEntity}} parameter representing the command block. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cCommandBlockEntity|CommandBlockEntity}}, [CallbackData])</pre> The function returns false if there is no command block, or if there is, it returns the bool value that the callback has returned." },
- DoWithDispenserAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a dispenser at the specified coords, calls the CallbackFunction with the {{cDispenserEntity}} parameter representing the dispenser. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cDispenserEntity|DispenserEntity}}, [CallbackData])</pre> The function returns false if there is no dispenser, or if there is, it returns the bool value that the callback has returned." },
- DoWithDropSpenserAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a dropper or a dispenser at the specified coords, calls the CallbackFunction with the {{cDropSpenserEntity}} parameter representing the dropper or dispenser. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cDropSpenserEntity|DropSpenserEntity}}, [CallbackData])</pre> Note that this can be used to access both dispensers and droppers in a similar way. The function returns false if there is neither dispenser nor dropper, or if there is, it returns the bool value that the callback has returned." },
- DoWithDropperAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a dropper at the specified coords, calls the CallbackFunction with the {{cDropperEntity}} parameter representing the dropper. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cDropperEntity|DropperEntity}}, [CallbackData])</pre> The function returns false if there is no dropper, or if there is, it returns the bool value that the callback has returned." },
- DoWithEntityByID = { Params = "EntityID, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If an entity with the specified ID exists, calls the callback with the {{cEntity}} parameter representing the entity. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cEntity|Entity}}, [CallbackData])</pre> The function returns false if the entity was not found, and it returns the same bool value that the callback has returned if the entity was found." },
- DoWithFlowerPotAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a flower pot at the specified coords, calls the CallbackFunction with the {{cFlowerPotEntity}} parameter representing the flower pot. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cFlowerPotEntity|FlowerPotEntity}}, [CallbackData])</pre> The function returns false if there is no flower pot, or if there is, it returns the bool value that the callback has returned." },
- DoWithFurnaceAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a furnace at the specified coords, calls the CallbackFunction with the {{cFurnaceEntity}} parameter representing the furnace. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cFurnaceEntity|FurnaceEntity}}, [CallbackData])</pre> The function returns false if there is no furnace, or if there is, it returns the bool value that the callback has returned." },
- DoWithMobHeadAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a mob head at the specified coords, calls the CallbackFunction with the {{cMobHeadEntity}} parameter representing the furnace. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cMobHeadEntity|MobHeadEntity}}, [CallbackData])</pre> The function returns false if there is no mob head, or if there is, it returns the bool value that the callback has returned." },
- DoWithNoteBlockAt = { Params = "BlockX, BlockY, BlockZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a note block at the specified coords, calls the CallbackFunction with the {{cNoteEntity}} parameter representing the note block. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cNoteEntity|NoteEntity}}, [CallbackData])</pre> The function returns false if there is no note block, or if there is, it returns the bool value that the callback has returned." },
- DoWithPlayer = { Params = "PlayerName, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a player of the specified name (exact match), calls the CallbackFunction with the {{cPlayer}} parameter representing the player. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cPlayer|Player}}, [CallbackData])</pre> The function returns false if the player was not found, or whatever bool value the callback returned if the player was found." },
+ DoWithBlockEntityAt = { Params = "BlockX, BlockY, BlockZ, CallbackFunction", Return = "bool", Notes = "If there is a block entity at the specified coords, calls the CallbackFunction with the {{cBlockEntity}} parameter representing the block entity. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cBlockEntity|BlockEntity}})</pre> The function returns false if there is no block entity, or if there is, it returns the bool value that the callback has returned. Use {{tolua}}.cast() to cast the Callback's BlockEntity parameter to the correct {{cBlockEntity}} descendant." },
+ DoWithBeaconAt = { Params = "BlockX, BlockY, BlockZ, CallbackFunction", Return = "bool", Notes = "If there is a beacon at the specified coords, calls the CallbackFunction with the {{cBeaconEntity}} parameter representing the beacon. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cBeaconEntity|BeaconEntity}})</pre> The function returns false if there is no beacon, or if there is, it returns the bool value that the callback has returned." },
+ DoWithChestAt = { Params = "BlockX, BlockY, BlockZ, CallbackFunction", Return = "bool", Notes = "If there is a chest at the specified coords, calls the CallbackFunction with the {{cChestEntity}} parameter representing the chest. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cChestEntity|ChestEntity}})</pre> The function returns false if there is no chest, or if there is, it returns the bool value that the callback has returned." },
+ DoWithCommandBlockAt = { Params = "BlockX, BlockY, BlockZ, CallbackFunction", Return = "bool", Notes = "If there is a command block at the specified coords, calls the CallbackFunction with the {{cCommandBlockEntity}} parameter representing the command block. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cCommandBlockEntity|CommandBlockEntity}})</pre> The function returns false if there is no command block, or if there is, it returns the bool value that the callback has returned." },
+ DoWithDispenserAt = { Params = "BlockX, BlockY, BlockZ, CallbackFunction", Return = "bool", Notes = "If there is a dispenser at the specified coords, calls the CallbackFunction with the {{cDispenserEntity}} parameter representing the dispenser. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cDispenserEntity|DispenserEntity}})</pre> The function returns false if there is no dispenser, or if there is, it returns the bool value that the callback has returned." },
+ DoWithDropSpenserAt = { Params = "BlockX, BlockY, BlockZ, CallbackFunction", Return = "bool", Notes = "If there is a dropper or a dispenser at the specified coords, calls the CallbackFunction with the {{cDropSpenserEntity}} parameter representing the dropper or dispenser. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cDropSpenserEntity|DropSpenserEntity}})</pre> Note that this can be used to access both dispensers and droppers in a similar way. The function returns false if there is neither dispenser nor dropper, or if there is, it returns the bool value that the callback has returned." },
+ DoWithDropperAt = { Params = "BlockX, BlockY, BlockZ, CallbackFunction", Return = "bool", Notes = "If there is a dropper at the specified coords, calls the CallbackFunction with the {{cDropperEntity}} parameter representing the dropper. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cDropperEntity|DropperEntity}})</pre> The function returns false if there is no dropper, or if there is, it returns the bool value that the callback has returned." },
+ DoWithEntityByID = { Params = "EntityID, CallbackFunction", Return = "bool", Notes = "If an entity with the specified ID exists, calls the callback with the {{cEntity}} parameter representing the entity. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cEntity|Entity}})</pre> The function returns false if the entity was not found, and it returns the same bool value that the callback has returned if the entity was found." },
+ DoWithFlowerPotAt = { Params = "BlockX, BlockY, BlockZ, CallbackFunction", Return = "bool", Notes = "If there is a flower pot at the specified coords, calls the CallbackFunction with the {{cFlowerPotEntity}} parameter representing the flower pot. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cFlowerPotEntity|FlowerPotEntity}})</pre> The function returns false if there is no flower pot, or if there is, it returns the bool value that the callback has returned." },
+ DoWithFurnaceAt = { Params = "BlockX, BlockY, BlockZ, CallbackFunction", Return = "bool", Notes = "If there is a furnace at the specified coords, calls the CallbackFunction with the {{cFurnaceEntity}} parameter representing the furnace. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cFurnaceEntity|FurnaceEntity}})</pre> The function returns false if there is no furnace, or if there is, it returns the bool value that the callback has returned." },
+ DoWithMobHeadAt = { Params = "BlockX, BlockY, BlockZ, CallbackFunction", Return = "bool", Notes = "If there is a mob head at the specified coords, calls the CallbackFunction with the {{cMobHeadEntity}} parameter representing the furnace. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cMobHeadEntity|MobHeadEntity}})</pre> The function returns false if there is no mob head, or if there is, it returns the bool value that the callback has returned." },
+ DoWithNoteBlockAt = { Params = "BlockX, BlockY, BlockZ, CallbackFunction", Return = "bool", Notes = "If there is a note block at the specified coords, calls the CallbackFunction with the {{cNoteEntity}} parameter representing the note block. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cNoteEntity|NoteEntity}})</pre> The function returns false if there is no note block, or if there is, it returns the bool value that the callback has returned." },
+ DoWithPlayer = { Params = "PlayerName, CallbackFunction", Return = "bool", Notes = "If there is a player of the specified name (exact match), calls the CallbackFunction with the {{cPlayer}} parameter representing the player. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cPlayer|Player}})</pre> The function returns false if the player was not found, or whatever bool value the callback returned if the player was found." },
+ DoWithPlayerByUUID = { Params = "PlayerUUID, CallbackFunction", Return = "bool", Notes = "If there is the player with the uuid, calls the CallbackFunction with the {{cPlayer}} parameter representing the player. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cPlayer|Player}})</pre> The function returns false if the player was not found, or whatever bool value the callback returned if the player was found." },
FastSetBlock =
{
- { Params = "X, Y, Z, BlockType, BlockMeta", Return = "", Notes = "Sets the block at the specified coords, without waking up the simulators or replacing the block entities for the previous block type. Do not use if the block being replaced has a block entity tied to it!" },
+ { Params = "BlockX, BlockY, BlockZ, BlockType, BlockMeta", Return = "", Notes = "Sets the block at the specified coords, without waking up the simulators or replacing the block entities for the previous block type. Do not use if the block being replaced has a block entity tied to it!" },
{ Params = "{{Vector3i|BlockCoords}}, BlockType, BlockMeta", Return = "", Notes = "Sets the block at the specified coords, without waking up the simulators or replacing the block entities for the previous block type. Do not use if the block being replaced has a block entity tied to it!" },
},
- FindAndDoWithPlayer = { Params = "PlayerNameHint, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a player of a name similar to the specified name (weighted-match), calls the CallbackFunction with the {{cPlayer}} parameter representing the player. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cPlayer|Player}}, [CallbackData])</pre> The function returns false if the player was not found, or whatever bool value the callback returned if the player was found. Note that the name matching is very loose, so it is a good idea to check the player name in the callback function." },
- DoWithPlayerByUUID = { Params = "PlayerUUID, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is the player with the uuid, calls the CallbackFunction with the {{cPlayer}} parameter representing the player. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cPlayer|Player}}, [CallbackData])</pre> The function returns false if the player was not found, or whatever bool value the callback returned if the player was found." },
- ForEachBlockEntityInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each block entity in the chunk. Returns true if all block entities in the chunk have been processed (including when there are zero block entities), or false if the callback has aborted the enumeration by returning true. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cBlockEntity|BlockEntity}}, [CallbackData])</pre> The callback should return false or no value to continue with the next block entity, or true to abort the enumeration. Use {{tolua}}.cast() to cast the Callback's BlockEntity parameter to the correct {{cBlockEntity}} descendant." },
- ForEachChestInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each chest in the chunk. Returns true if all chests in the chunk have been processed (including when there are zero chests), or false if the callback has aborted the enumeration by returning true. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cChestEntity|ChestEntity}}, [CallbackData])</pre> The callback should return false or no value to continue with the next chest, or true to abort the enumeration." },
- ForEachEntity = { Params = "CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each entity in the loaded world. Returns true if all the entities have been processed (including when there are zero entities), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cEntity|Entity}}, [CallbackData])</pre> The callback should return false or no value to continue with the next entity, or true to abort the enumeration." },
+ FindAndDoWithPlayer = { Params = "PlayerNameHint, CallbackFunction", Return = "bool", Notes = "If there is a player of a name similar to the specified name (weighted-match), calls the CallbackFunction with the {{cPlayer}} parameter representing the player. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cPlayer|Player}})</pre> The function returns false if the player was not found, or whatever bool value the callback returned if the player was found. Note that the name matching is very loose, so it is a good idea to check the player name in the callback function." },
+ ForEachBlockEntityInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction", Return = "bool", Notes = "Calls the specified callback for each block entity in the chunk. Returns true if all block entities in the chunk have been processed (including when there are zero block entities), or false if the callback has aborted the enumeration by returning true. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cBlockEntity|BlockEntity}})</pre> The callback should return false or no value to continue with the next block entity, or true to abort the enumeration. Use {{tolua}}.cast() to cast the Callback's BlockEntity parameter to the correct {{cBlockEntity}} descendant." },
+ ForEachChestInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction", Return = "bool", Notes = "Calls the specified callback for each chest in the chunk. Returns true if all chests in the chunk have been processed (including when there are zero chests), or false if the callback has aborted the enumeration by returning true. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cChestEntity|ChestEntity}})</pre> The callback should return false or no value to continue with the next chest, or true to abort the enumeration." },
+ ForEachEntity = { Params = "CallbackFunction", Return = "bool", Notes = "Calls the specified callback for each entity in the loaded world. Returns true if all the entities have been processed (including when there are zero entities), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cEntity|Entity}})</pre> The callback should return false or no value to continue with the next entity, or true to abort the enumeration." },
ForEachEntityInBox = { Params = "{{cBoundingBox|Box}}, CallbackFunction", Return = "bool", Notes = "Calls the specified callback for each entity in the specified bounding box. Returns true if all the entities have been processed (including when there are zero entities), or false if the callback function has aborted the enumeration by returning true. If any chunk within the bounding box is not valid, it is silently skipped without any notification. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cEntity|Entity}})</pre> The callback should return false or no value to continue with the next entity, or true to abort the enumeration." },
- ForEachEntityInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each entity in the specified chunk. Returns true if all the entities have been processed (including when there are zero entities), or false if the chunk is not loaded or the callback function has aborted the enumeration by returning true. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cEntity|Entity}}, [CallbackData])</pre> The callback should return false or no value to continue with the next entity, or true to abort the enumeration." },
- ForEachFurnaceInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each furnace in the chunk. Returns true if all furnaces in the chunk have been processed (including when there are zero furnaces), or false if the callback has aborted the enumeration by returning true. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cFurnaceEntity|FurnaceEntity}}, [CallbackData])</pre> The callback should return false or no value to continue with the next furnace, or true to abort the enumeration." },
- ForEachPlayer = { Params = "CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each player in the loaded world. Returns true if all the players have been processed (including when there are zero players), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cPlayer|Player}}, [CallbackData])</pre> The callback should return false or no value to continue with the next player, or true to abort the enumeration." },
+ ForEachEntityInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction", Return = "bool", Notes = "Calls the specified callback for each entity in the specified chunk. Returns true if all the entities have been processed (including when there are zero entities), or false if the chunk is not loaded or the callback function has aborted the enumeration by returning true. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cEntity|Entity}})</pre> The callback should return false or no value to continue with the next entity, or true to abort the enumeration." },
+ ForEachFurnaceInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction", Return = "bool", Notes = "Calls the specified callback for each furnace in the chunk. Returns true if all furnaces in the chunk have been processed (including when there are zero furnaces), or false if the callback has aborted the enumeration by returning true. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cFurnaceEntity|FurnaceEntity}})</pre> The callback should return false or no value to continue with the next furnace, or true to abort the enumeration." },
+ ForEachPlayer = { Params = "CallbackFunction", Return = "bool", Notes = "Calls the specified callback for each player in the loaded world. Returns true if all the players have been processed (including when there are zero players), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cPlayer|Player}})</pre> The callback should return false or no value to continue with the next player, or true to abort the enumeration." },
GenerateChunk = { Params = "ChunkX, ChunkZ", Return = "", Notes = "Queues the specified chunk in the chunk generator. Ignored if the chunk is already generated (use RegenerateChunk() to force chunk re-generation)." },
GetBiomeAt = { Params = "BlockX, BlockZ", Return = "eBiome", Notes = "Returns the biome at the specified coords. Reads the biome from the chunk, if it is loaded, otherwise it uses the chunk generator to provide the biome value." },
GetBlock =
diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua
index 6580e9dbc..bffc6e844 100644
--- a/MCServer/Plugins/Debuggers/Debuggers.lua
+++ b/MCServer/Plugins/Debuggers/Debuggers.lua
@@ -82,7 +82,7 @@ function Initialize(a_Plugin)
a_CBPlayer:GetWorld():DoWithEntityByID( -- This will crash the server in #1889
a_CBEntity:GetUniqueID(),
function(Entity)
- LOG("RightClicking an entity, crash #1889 fixed")
+ LOG("RightClicking an entity, crash #1889 fixed. Entity is a " .. tolua.type(Entity))
end
)
end
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp
index 468e54f32..38e008b2a 100644
--- a/src/Bindings/LuaState.cpp
+++ b/src/Bindings/LuaState.cpp
@@ -1013,6 +1013,24 @@ void cLuaState::GetStackValue(int a_StackPos, pBoundingBox & a_ReturnedVal)
+void cLuaState::GetStackValue(int a_StackPos, pMapManager & a_ReturnedVal)
+{
+ if (lua_isnil(m_LuaState, a_StackPos))
+ {
+ a_ReturnedVal = nullptr;
+ return;
+ }
+ tolua_Error err;
+ if (tolua_isusertype(m_LuaState, a_StackPos, "cMapManager", false, &err))
+ {
+ a_ReturnedVal = *(reinterpret_cast<cMapManager **>(lua_touserdata(m_LuaState, a_StackPos)));
+ }
+}
+
+
+
+
+
void cLuaState::GetStackValue(int a_StackPos, pPluginManager & a_ReturnedVal)
{
if (lua_isnil(m_LuaState, a_StackPos))
diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h
index b77556117..a6e121eb7 100644
--- a/src/Bindings/LuaState.h
+++ b/src/Bindings/LuaState.h
@@ -50,6 +50,7 @@ class cItems;
class cLuaServerHandle;
class cLuaTCPLink;
class cLuaUDPEndpoint;
+class cMapManager;
class cMonster;
class cPickup;
class cPlayer;
@@ -68,6 +69,7 @@ struct HTTPTemplateRequest;
struct TakeDamageInfo;
typedef cBoundingBox * pBoundingBox;
+typedef cMapManager * pMapManager;
typedef cPluginManager * pPluginManager;
typedef cRoot * pRoot;
typedef cScoreboard * pScoreboard;
@@ -248,6 +250,7 @@ public:
void GetStackValue(int a_StackPos, eWeather & a_Value);
void GetStackValue(int a_StackPos, int & a_Value);
void GetStackValue(int a_StackPos, pBoundingBox & a_Value);
+ void GetStackValue(int a_StackPos, pMapManager & a_Value);
void GetStackValue(int a_StackPos, pPluginManager & a_Value);
void GetStackValue(int a_StackPos, pRoot & a_Value);
void GetStackValue(int a_StackPos, pScoreboard & a_Value);
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index ddd77b75b..253d57297 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -627,87 +627,59 @@ static int tolua_StaticDoWith(lua_State * tolua_S)
template <
class Ty1,
class Ty2,
- bool (Ty1::*Func1)(UInt32, cItemCallback<Ty2> &)
+ bool (Ty1::*DoWithFn)(UInt32, cItemCallback<Ty2> &)
>
-static int tolua_DoWithID(lua_State* tolua_S)
+static int tolua_DoWithID(lua_State * tolua_S)
{
- int NumArgs = lua_gettop(tolua_S) - 1; /* This includes 'self' */
- if ((NumArgs != 2) && (NumArgs != 3))
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 2 or 3 arguments, got %i", NumArgs);
- }
-
- Ty1 * self = (Ty1 *)tolua_tousertype(tolua_S, 1, nullptr);
-
- int ItemID = (int)tolua_tonumber(tolua_S, 2, 0);
- if (!lua_isfunction(tolua_S, 3))
+ // Check params:
+ cLuaState L(tolua_S);
+ if (
+ !L.CheckParamNumber(2) ||
+ !L.CheckParamFunction(3)
+ )
{
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a function for parameter #2", NumArgs);
+ return 0;
}
- /* luaL_ref gets reference to value on top of the stack, the table is the last argument and therefore on the top */
- int TableRef = LUA_REFNIL;
- if (NumArgs == 3)
+ // Get parameters:
+ Ty1 * Self = nullptr;
+ int ItemID;
+ cLuaState::cRef FnRef;
+ L.GetStackValues(1, Self, ItemID, FnRef);
+ if (Self == nullptr)
{
- TableRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
- if (TableRef == LUA_REFNIL)
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get value reference of parameter #3", NumArgs);
- }
+ return lua_do_error(tolua_S, "Error in function call '#funcname#': Invalid 'self'");
}
-
- /* table value is popped, and now function is on top of the stack */
- int FuncRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
- if (FuncRef == LUA_REFNIL)
+ if (!FnRef.IsValid())
{
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get function reference of parameter #2", NumArgs);
+ return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a valid callback function for parameter #2");
}
class cLuaCallback : public cItemCallback<Ty2>
{
public:
- cLuaCallback(lua_State * a_LuaState, int a_FuncRef, int a_TableRef) :
- LuaState(a_LuaState),
- FuncRef(a_FuncRef),
- TableRef(a_TableRef)
+ cLuaCallback(cLuaState & a_LuaState, cLuaState::cRef & a_FnRef):
+ m_LuaState(a_LuaState),
+ m_FnRef(a_FnRef)
{
}
private:
virtual bool Item(Ty2 * a_Item) override
{
- lua_rawgeti(LuaState, LUA_REGISTRYINDEX, FuncRef); // Push function to call
- tolua_pushusertype(LuaState, a_Item, a_Item->GetClass()); // Push the item
- if (TableRef != LUA_REFNIL)
- {
- lua_rawgeti(LuaState, LUA_REGISTRYINDEX, TableRef); // Push the optional callbackdata param
- }
-
- int s = lua_pcall(LuaState, (TableRef == LUA_REFNIL ? 1 : 2), 1, 0);
- if (cLuaState::ReportErrors(LuaState, s))
- {
- return true; // Abort enumeration
- }
- if (lua_isboolean(LuaState, -1))
- {
- return (tolua_toboolean(LuaState, -1, 0) > 0);
- }
- return false; /* Continue enumeration */
+ bool ret = false;
+ m_LuaState.Call(m_FnRef, a_Item, cLuaState::Return, ret);
+ return ret;
}
- lua_State * LuaState;
- int FuncRef;
- int TableRef;
- } Callback(tolua_S, FuncRef, TableRef);
-
-
- bool bRetVal = (self->*Func1)(ItemID, Callback);
+ cLuaState & m_LuaState;
+ cLuaState::cRef & m_FnRef;
+ } Callback(L, FnRef);
- /* Unreference the values again, so the LUA_REGISTRYINDEX can make place for other references */
- luaL_unref(tolua_S, LUA_REGISTRYINDEX, TableRef);
- luaL_unref(tolua_S, LUA_REGISTRYINDEX, FuncRef);
+ // Call the DoWith function:
+ bool res = (Self->*DoWithFn)(ItemID, Callback);
- /* Push return value on stack */
- tolua_pushboolean(tolua_S, bRetVal);
+ // Push the result as the return value:
+ L.Push(res);
return 1;
}
@@ -718,92 +690,59 @@ static int tolua_DoWithID(lua_State* tolua_S)
template <
class Ty1,
class Ty2,
- bool (Ty1::*Func1)(int, int, int, cItemCallback<Ty2> &)
+ bool (Ty1::*DoWithFn)(int, int, int, cItemCallback<Ty2> &)
>
static int tolua_DoWithXYZ(lua_State* tolua_S)
{
- int NumArgs = lua_gettop(tolua_S) - 1; /* This includes 'self' */
- if ((NumArgs != 4) && (NumArgs != 5))
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 4 or 5 arguments, got %i", NumArgs);
- }
-
- Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, nullptr);
- if (!lua_isnumber(tolua_S, 2) || !lua_isnumber(tolua_S, 3) || !lua_isnumber(tolua_S, 4))
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a number for parameters #1, #2 and #3");
- }
-
- int ItemX = ((int)tolua_tonumber(tolua_S, 2, 0));
- int ItemY = ((int)tolua_tonumber(tolua_S, 3, 0));
- int ItemZ = ((int)tolua_tonumber(tolua_S, 4, 0));
- if (!lua_isfunction(tolua_S, 5))
+ // Check params:
+ cLuaState L(tolua_S);
+ if (
+ !L.CheckParamNumber(2, 5) ||
+ !L.CheckParamFunction(6)
+ )
{
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a function for parameter #4");
+ return 0;
}
- /* luaL_ref gets reference to value on top of the stack, the table is the last argument and therefore on the top */
- int TableRef = LUA_REFNIL;
- if (NumArgs == 5)
+ // Get parameters:
+ Ty1 * Self = nullptr;
+ int BlockX, BlockY, BlockZ;
+ cLuaState::cRef FnRef;
+ L.GetStackValues(1, Self, BlockX, BlockY, BlockZ, FnRef);
+ if (Self == nullptr)
{
- TableRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
- if (TableRef == LUA_REFNIL)
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get value reference of parameter #5");
- }
+ return lua_do_error(tolua_S, "Error in function call '#funcname#': Invalid 'self'");
}
-
- /* table value is popped, and now function is on top of the stack */
- int FuncRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
- if (FuncRef == LUA_REFNIL)
+ if (!FnRef.IsValid())
{
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get function reference of parameter #4");
+ return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a valid callback function for parameter #5");
}
class cLuaCallback : public cItemCallback<Ty2>
{
public:
- cLuaCallback(lua_State* a_LuaState, int a_FuncRef, int a_TableRef):
- LuaState(a_LuaState),
- FuncRef(a_FuncRef),
- TableRef(a_TableRef)
+ cLuaCallback(cLuaState & a_LuaState, cLuaState::cRef & a_FnRef):
+ m_LuaState(a_LuaState),
+ m_FnRef(a_FnRef)
{
}
private:
virtual bool Item(Ty2 * a_Item) override
{
- lua_rawgeti(LuaState, LUA_REGISTRYINDEX, FuncRef); /* Push function reference */
- tolua_pushusertype(LuaState, a_Item, Ty2::GetClassStatic());
- if (TableRef != LUA_REFNIL)
- {
- lua_rawgeti(LuaState, LUA_REGISTRYINDEX, TableRef); /* Push table reference */
- }
-
- int s = lua_pcall(LuaState, (TableRef == LUA_REFNIL ? 1 : 2), 1, 0);
- if (cLuaState::ReportErrors(LuaState, s))
- {
- return true; // Abort enumeration
- }
- if (lua_isboolean(LuaState, -1))
- {
- return (tolua_toboolean(LuaState, -1, 0) > 0);
- }
- return false; /* Continue enumeration */
+ bool ret = false;
+ m_LuaState.Call(m_FnRef, a_Item, cLuaState::Return, ret);
+ return ret;
}
- lua_State * LuaState;
- int FuncRef;
- int TableRef;
- } Callback(tolua_S, FuncRef, TableRef);
-
- bool bRetVal = (self->*Func1)(ItemX, ItemY, ItemZ, Callback);
+ cLuaState & m_LuaState;
+ cLuaState::cRef & m_FnRef;
+ } Callback(L, FnRef);
- /* Unreference the values again, so the LUA_REGISTRYINDEX can make place for other references */
- luaL_unref(tolua_S, LUA_REGISTRYINDEX, TableRef);
- luaL_unref(tolua_S, LUA_REGISTRYINDEX, FuncRef);
+ // Call the DoWith function:
+ bool res = (Self->*DoWithFn)(BlockX, BlockY, BlockZ, Callback);
- /* Push return value on stack */
- tolua_pushboolean(tolua_S, bRetVal);
+ // Push the result as the return value:
+ L.Push(res);
return 1;
}
@@ -814,93 +753,59 @@ static int tolua_DoWithXYZ(lua_State* tolua_S)
template <
class Ty1,
class Ty2,
- bool (Ty1::*Func1)(int, int, cItemCallback<Ty2> &)
+ bool (Ty1::*ForEachFn)(int, int, cItemCallback<Ty2> &)
>
static int tolua_ForEachInChunk(lua_State * tolua_S)
{
- int NumArgs = lua_gettop(tolua_S) - 1; /* This includes 'self' */
- if ((NumArgs != 3) && (NumArgs != 4))
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 3 or 4 arguments, got %i", NumArgs);
- }
-
- Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, nullptr);
- if (!lua_isnumber(tolua_S, 2) || !lua_isnumber(tolua_S, 3))
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a number for parameters #1 and #2");
- }
-
- int ChunkX = ((int)tolua_tonumber(tolua_S, 2, 0));
- int ChunkZ = ((int)tolua_tonumber(tolua_S, 3, 0));
-
- if (!lua_isfunction(tolua_S, 4))
+ // Check params:
+ cLuaState L(tolua_S);
+ if (
+ !L.CheckParamNumber(2, 4) ||
+ !L.CheckParamFunction(5)
+ )
{
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a function for parameter #3");
+ return 0;
}
- /* luaL_ref gets reference to value on top of the stack, the table is the last argument and therefore on the top */
- int TableRef = LUA_REFNIL;
- if (NumArgs == 4)
+ // Get parameters:
+ Ty1 * Self = nullptr;
+ int ChunkX, ChunkZ;
+ cLuaState::cRef FnRef;
+ L.GetStackValues(1, Self, ChunkX, ChunkZ, FnRef);
+ if (Self == nullptr)
{
- TableRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
- if (TableRef == LUA_REFNIL)
- {
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get value reference of parameter #4");
- }
+ return lua_do_error(tolua_S, "Error in function call '#funcname#': Invalid 'self'");
}
-
- /* table value is popped, and now function is on top of the stack */
- int FuncRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
- if (FuncRef == LUA_REFNIL)
+ if (!FnRef.IsValid())
{
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get function reference of parameter #3");
+ return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a valid callback function for parameter #4");
}
class cLuaCallback : public cItemCallback<Ty2>
{
public:
- cLuaCallback(lua_State* a_LuaState, int a_FuncRef, int a_TableRef):
- LuaState(a_LuaState),
- FuncRef(a_FuncRef),
- TableRef(a_TableRef)
+ cLuaCallback(cLuaState & a_LuaState, cLuaState::cRef & a_FnRef):
+ m_LuaState(a_LuaState),
+ m_FnRef(a_FnRef)
{
}
private:
virtual bool Item(Ty2 * a_Item) override
{
- lua_rawgeti(LuaState, LUA_REGISTRYINDEX, FuncRef); /* Push function reference */
- tolua_pushusertype(LuaState, a_Item, Ty2::GetClassStatic());
- if (TableRef != LUA_REFNIL)
- {
- lua_rawgeti(LuaState, LUA_REGISTRYINDEX, TableRef); /* Push table reference */
- }
-
- int s = lua_pcall(LuaState, (TableRef == LUA_REFNIL ? 1 : 2), 1, 0);
- if (cLuaState::ReportErrors(LuaState, s))
- {
- return true; /* Abort enumeration */
- }
-
- if (lua_isboolean(LuaState, -1))
- {
- return (tolua_toboolean(LuaState, -1, 0) > 0);
- }
- return false; /* Continue enumeration */
+ bool ret = false;
+ m_LuaState.Call(m_FnRef, a_Item, cLuaState::Return, ret);
+ return ret;
}
- lua_State * LuaState;
- int FuncRef;
- int TableRef;
- } Callback(tolua_S, FuncRef, TableRef);
-
- bool bRetVal = (self->*Func1)(ChunkX, ChunkZ, Callback);
+ cLuaState & m_LuaState;
+ cLuaState::cRef & m_FnRef;
+ } Callback(L, FnRef);
- /* Unreference the values again, so the LUA_REGISTRYINDEX can make place for other references */
- luaL_unref(tolua_S, LUA_REGISTRYINDEX, TableRef);
- luaL_unref(tolua_S, LUA_REGISTRYINDEX, FuncRef);
+ // Call the DoWith function:
+ bool res = (Self->*ForEachFn)(ChunkX, ChunkZ, Callback);
- /* Push return value on stack */
- tolua_pushboolean(tolua_S, bRetVal);
+ // Push the result as the return value:
+ L.Push(res);
return 1;
}
@@ -911,7 +816,7 @@ static int tolua_ForEachInChunk(lua_State * tolua_S)
template <
class Ty1,
class Ty2,
- bool (Ty1::*Func1)(const cBoundingBox &, cItemCallback<Ty2> &)
+ bool (Ty1::*ForEachFn)(const cBoundingBox &, cItemCallback<Ty2> &)
>
static int tolua_ForEachInBox(lua_State * tolua_S)
{
@@ -930,16 +835,18 @@ static int tolua_ForEachInBox(lua_State * tolua_S)
// Get the params:
Ty1 * Self = nullptr;
cBoundingBox * Box = nullptr;
- L.GetStackValues(1, Self, Box);
+ cLuaState::cRef FnRef;
+ L.GetStackValues(1, Self, Box, FnRef);
if ((Self == nullptr) || (Box == nullptr))
{
LOGWARNING("Invalid world (%p) or boundingbox (%p)", Self, Box);
L.LogStackTrace();
return 0;
}
-
- // Create a reference for the function:
- cLuaState::cRef FnRef(L, 3);
+ if (!FnRef.IsValid())
+ {
+ return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a valid callback function for parameter #2");
+ }
// Callback wrapper for the Lua function:
class cLuaCallback : public cItemCallback<Ty2>
@@ -970,12 +877,10 @@ static int tolua_ForEachInBox(lua_State * tolua_S)
}
} Callback(L, FnRef);
- bool bRetVal = (Self->*Func1)(*Box, Callback);
-
- FnRef.UnRef();
+ bool res = (Self->*ForEachFn)(*Box, Callback);
- /* Push return value on stack */
- tolua_pushboolean(tolua_S, bRetVal);
+ // Push the result as the return value:
+ L.Push(res);
return 1;
}
@@ -986,7 +891,7 @@ static int tolua_ForEachInBox(lua_State * tolua_S)
template <
class Ty1,
class Ty2,
- bool (Ty1::*Func1)(cItemCallback<Ty2> &)
+ bool (Ty1::*ForEachFn)(cItemCallback<Ty2> &)
>
static int tolua_ForEach(lua_State * tolua_S)
{
@@ -1001,13 +906,17 @@ static int tolua_ForEach(lua_State * tolua_S)
}
// Get the params:
- Ty1 * self;
- L.GetStackValues(1, self);
- cLuaState::cRef FnRef(L, 2);
- if (self == nullptr)
+ Ty1 * Self = nullptr;
+ cLuaState::cRef FnRef;
+ L.GetStackValues(1, Self, FnRef);
+ if (Self == nullptr)
{
return lua_do_error(tolua_S, "Error in function call '#funcname#': Invalid 'self'.");
}
+ if (!FnRef.IsValid())
+ {
+ return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a valid callback function for parameter #1");
+ }
class cLuaCallback : public cItemCallback<Ty2>
{
@@ -1031,7 +940,7 @@ static int tolua_ForEach(lua_State * tolua_S)
} Callback(L, FnRef);
// Call the enumeration:
- bool res = (self->*Func1)(Callback);
+ bool res = (Self->*ForEachFn)(Callback);
// Push the return value:
L.Push(res);
@@ -1046,7 +955,7 @@ static int tolua_ForEach(lua_State * tolua_S)
template <
class Ty1,
class Ty2,
- bool (Ty1::*Func1)(cItemCallback<Ty2> &)
+ bool (Ty1::*ForEachFn)(cItemCallback<Ty2> &)
>
static int tolua_StaticForEach(lua_State * tolua_S)
{
@@ -1062,6 +971,10 @@ static int tolua_StaticForEach(lua_State * tolua_S)
// Get the params:
cLuaState::cRef FnRef(L, 2);
+ if (!FnRef.IsValid())
+ {
+ return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a valid callback function for parameter #1");
+ }
class cLuaCallback : public cItemCallback<Ty2>
{
@@ -1085,7 +998,7 @@ static int tolua_StaticForEach(lua_State * tolua_S)
} Callback(L, FnRef);
// Call the enumeration:
- bool res = (Ty1::Get()->*Func1)(Callback);
+ bool res = (Ty1::Get()->*ForEachFn)(Callback);
// Push the return value:
L.Push(res);
@@ -1100,51 +1013,43 @@ static int tolua_cWorld_GetBlockInfo(lua_State * tolua_S)
{
// Exported manually, because tolua would generate useless additional parameters (a_BlockType .. a_BlockSkyLight)
// Function signature: GetBlockInfo(BlockX, BlockY, BlockZ) -> BlockValid, [BlockType, BlockMeta, BlockSkyLight, BlockBlockLight]
- #ifndef TOLUA_RELEASE
- tolua_Error tolua_err;
+
+ // Check params:
+ cLuaState L(tolua_S);
if (
- !tolua_isusertype (tolua_S, 1, "cWorld", 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 2, 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 3, 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 4, 0, &tolua_err) ||
- !tolua_isnoobj (tolua_S, 5, &tolua_err)
- )
- goto tolua_lerror;
- else
- #endif
+ !L.CheckParamUserType(1, "cWorld") ||
+ !L.CheckParamNumber(2, 4) ||
+ !L.CheckParamEnd(5)
+ )
{
- cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, nullptr);
- int BlockX = (int) tolua_tonumber (tolua_S, 2, 0);
- int BlockY = (int) tolua_tonumber (tolua_S, 3, 0);
- int BlockZ = (int) tolua_tonumber (tolua_S, 4, 0);
- #ifndef TOLUA_RELEASE
- if (self == nullptr)
- {
- tolua_error(tolua_S, "invalid 'self' in function 'GetBlockInfo'", nullptr);
- }
- #endif
- {
- BLOCKTYPE BlockType;
- NIBBLETYPE BlockMeta, BlockSkyLight, BlockBlockLight;
- bool res = self->GetBlockInfo(BlockX, BlockY, BlockZ, BlockType, BlockMeta, BlockSkyLight, BlockBlockLight);
- tolua_pushboolean(tolua_S, res ? 1 : 0);
- if (res)
- {
- tolua_pushnumber(tolua_S, BlockType);
- tolua_pushnumber(tolua_S, BlockMeta);
- tolua_pushnumber(tolua_S, BlockSkyLight);
- tolua_pushnumber(tolua_S, BlockBlockLight);
- return 5;
- }
- }
+ return 0;
+ }
+
+ // Get params:
+ cWorld * Self = nullptr;
+ int BlockX, BlockY, BlockZ;
+ L.GetStackValues(1, Self, BlockX, BlockY, BlockZ);
+ if (Self == nullptr)
+ {
+ return lua_do_error(tolua_S, "Error in function call '#funcname#': Invalid 'self'");
+ }
+
+ // Call the function:
+ BLOCKTYPE BlockType;
+ NIBBLETYPE BlockMeta, BlockSkyLight, BlockBlockLight;
+ bool res = Self->GetBlockInfo(BlockX, BlockY, BlockZ, BlockType, BlockMeta, BlockSkyLight, BlockBlockLight);
+
+ // Push the returned values:
+ L.Push(res);
+ if (res)
+ {
+ L.Push(BlockType);
+ L.Push(BlockMeta);
+ L.Push(BlockSkyLight);
+ L.Push(BlockBlockLight);
+ return 5;
}
return 1;
-
- #ifndef TOLUA_RELEASE
-tolua_lerror:
- tolua_error(tolua_S, "#ferror in function 'GetBlockInfo'.", &tolua_err);
- return 0;
- #endif
}
@@ -1155,49 +1060,41 @@ static int tolua_cWorld_GetBlockTypeMeta(lua_State * tolua_S)
{
// Exported manually, because tolua would generate useless additional parameters (a_BlockType, a_BlockMeta)
// Function signature: GetBlockTypeMeta(BlockX, BlockY, BlockZ) -> BlockValid, [BlockType, BlockMeta]
- #ifndef TOLUA_RELEASE
- tolua_Error tolua_err;
+
+ // Check params:
+ cLuaState L(tolua_S);
if (
- !tolua_isusertype (tolua_S, 1, "cWorld", 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 2, 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 3, 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 4, 0, &tolua_err) ||
- !tolua_isnoobj (tolua_S, 5, &tolua_err)
- )
- goto tolua_lerror;
- else
- #endif
+ !L.CheckParamUserType(1, "cWorld") ||
+ !L.CheckParamNumber(2, 4) ||
+ !L.CheckParamEnd(5)
+ )
{
- cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, nullptr);
- int BlockX = (int) tolua_tonumber (tolua_S, 2, 0);
- int BlockY = (int) tolua_tonumber (tolua_S, 3, 0);
- int BlockZ = (int) tolua_tonumber (tolua_S, 4, 0);
- #ifndef TOLUA_RELEASE
- if (self == nullptr)
- {
- tolua_error(tolua_S, "invalid 'self' in function 'GetBlockTypeMeta'", nullptr);
- }
- #endif
- {
- BLOCKTYPE BlockType;
- NIBBLETYPE BlockMeta;
- bool res = self->GetBlockTypeMeta(BlockX, BlockY, BlockZ, BlockType, BlockMeta);
- tolua_pushboolean(tolua_S, res ? 1 : 0);
- if (res)
- {
- tolua_pushnumber(tolua_S, BlockType);
- tolua_pushnumber(tolua_S, BlockMeta);
- return 3;
- }
- }
+ return 0;
+ }
+
+ // Get params:
+ cWorld * Self = nullptr;
+ int BlockX, BlockY, BlockZ;
+ L.GetStackValues(1, Self, BlockX, BlockY, BlockZ);
+ if (Self == nullptr)
+ {
+ return lua_do_error(tolua_S, "Error in function call '#funcname#': Invalid 'self'");
+ }
+
+ // Call the function:
+ BLOCKTYPE BlockType;
+ NIBBLETYPE BlockMeta;
+ bool res = Self->GetBlockTypeMeta(BlockX, BlockY, BlockZ, BlockType, BlockMeta);
+
+ // Push the returned values:
+ L.Push(res);
+ if (res)
+ {
+ L.Push(BlockType);
+ L.Push(BlockMeta);
+ return 3;
}
return 1;
-
- #ifndef TOLUA_RELEASE
-tolua_lerror:
- tolua_error(tolua_S, "#ferror in function 'GetBlockTypeMeta'.", &tolua_err);
- return 0;
- #endif
}
@@ -1207,50 +1104,42 @@ tolua_lerror:
static int tolua_cWorld_GetSignLines(lua_State * tolua_S)
{
// Exported manually, because tolua would generate useless additional parameters (a_Line1 .. a_Line4)
- #ifndef TOLUA_RELEASE
- tolua_Error tolua_err;
+
+ // Check params:
+ cLuaState L(tolua_S);
if (
- !tolua_isusertype (tolua_S, 1, "cWorld", 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 2, 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 3, 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 4, 0, &tolua_err) ||
- !tolua_isnoobj (tolua_S, 10, &tolua_err)
- )
- goto tolua_lerror;
- else
- #endif
+ !L.CheckParamUserType(1, "cWorld") ||
+ !L.CheckParamNumber(2, 4) ||
+ !L.CheckParamEnd(5)
+ )
{
- cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, nullptr);
- int BlockX = (int) tolua_tonumber (tolua_S, 2, 0);
- int BlockY = (int) tolua_tonumber (tolua_S, 3, 0);
- int BlockZ = (int) tolua_tonumber (tolua_S, 4, 0);
- #ifndef TOLUA_RELEASE
- if (self == nullptr)
- {
- tolua_error(tolua_S, "invalid 'self' in function 'GetSignLines'", nullptr);
- }
- #endif
- {
- AString Line1, Line2, Line3, Line4;
- bool res = self->GetSignLines(BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4);
- tolua_pushboolean(tolua_S, res ? 1 : 0);
- if (res)
- {
- tolua_pushstring(tolua_S, Line1.c_str());
- tolua_pushstring(tolua_S, Line2.c_str());
- tolua_pushstring(tolua_S, Line3.c_str());
- tolua_pushstring(tolua_S, Line4.c_str());
- return 5;
- }
- }
+ return 0;
+ }
+
+ // Get params:
+ cWorld * Self = nullptr;
+ int BlockX, BlockY, BlockZ;
+ L.GetStackValues(1, Self, BlockX, BlockY, BlockZ);
+ if (Self == nullptr)
+ {
+ return lua_do_error(tolua_S, "Error in function call '#funcname#': Invalid 'self'");
+ }
+
+ // Call the function:
+ AString Line1, Line2, Line3, Line4;
+ bool res = Self->GetSignLines(BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4);
+
+ // Push the returned values:
+ L.Push(res);
+ if (res)
+ {
+ L.Push(Line1);
+ L.Push(Line2);
+ L.Push(Line3);
+ L.Push(Line4);
+ return 5;
}
return 1;
-
- #ifndef TOLUA_RELEASE
-tolua_lerror:
- tolua_error(tolua_S, "#ferror in function 'GetSignLines'.", &tolua_err);
- return 0;
- #endif
}
@@ -1260,51 +1149,35 @@ tolua_lerror:
static int tolua_cWorld_SetSignLines(lua_State * tolua_S)
{
// Exported manually, because tolua would generate useless additional return values (a_Line1 .. a_Line4)
- #ifndef TOLUA_RELEASE
- tolua_Error tolua_err;
+
+ // Check params:
+ cLuaState L(tolua_S);
if (
- !tolua_isusertype (tolua_S, 1, "cWorld", 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 2, 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 3, 0, &tolua_err) ||
- !tolua_isnumber (tolua_S, 4, 0, &tolua_err) ||
- !tolua_iscppstring(tolua_S, 5, 0, &tolua_err) ||
- !tolua_iscppstring(tolua_S, 6, 0, &tolua_err) ||
- !tolua_iscppstring(tolua_S, 7, 0, &tolua_err) ||
- !tolua_iscppstring(tolua_S, 8, 0, &tolua_err) ||
- !tolua_isusertype (tolua_S, 9, "cPlayer", 1, &tolua_err) ||
- !tolua_isnoobj (tolua_S, 10, &tolua_err)
- )
- goto tolua_lerror;
- else
- #endif
+ !L.CheckParamUserType(1, "cWorld") ||
+ !L.CheckParamNumber(2, 4) ||
+ !L.CheckParamString(5, 8) ||
+ !L.CheckParamEnd(9)
+ )
{
- cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, nullptr);
- int BlockX = (int) tolua_tonumber (tolua_S, 2, 0);
- int BlockY = (int) tolua_tonumber (tolua_S, 3, 0);
- int BlockZ = (int) tolua_tonumber (tolua_S, 4, 0);
- const AString Line1 = tolua_tocppstring(tolua_S, 5, 0);
- const AString Line2 = tolua_tocppstring(tolua_S, 6, 0);
- const AString Line3 = tolua_tocppstring(tolua_S, 7, 0);
- const AString Line4 = tolua_tocppstring(tolua_S, 8, 0);
- cPlayer * Player = (cPlayer *)tolua_tousertype (tolua_S, 9, nullptr);
- #ifndef TOLUA_RELEASE
- if (self == nullptr)
- {
- tolua_error(tolua_S, "invalid 'self' in function 'SetSignLines'", nullptr);
- }
- #endif
- {
- bool res = self->SetSignLines(BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4, Player);
- tolua_pushboolean(tolua_S, res ? 1 : 0);
- }
+ return 0;
+ }
+
+ // Get params:
+ cWorld * Self = nullptr;
+ int BlockX, BlockY, BlockZ;
+ AString Line1, Line2, Line3, Line4;
+ L.GetStackValues(1, Self, BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4);
+ if (Self == nullptr)
+ {
+ return lua_do_error(tolua_S, "Error in function call '#funcname#': Invalid 'self'");
}
+
+ // Call the function:
+ bool res = Self->SetSignLines(BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4);
+
+ // Push the returned values:
+ L.Push(res);
return 1;
-
- #ifndef TOLUA_RELEASE
-tolua_lerror:
- tolua_error(tolua_S, "#ferror in function 'SetSignLines'.", &tolua_err);
- return 0;
- #endif
}