1
0

Merge pull request #1894 from mc-server/RefactorManualBindingsTemplates

Refactored ManualBindings' callbacks using templates.
This commit is contained in:
Mattes D 2015-04-23 22:52:34 +02:00
commit 0bfcd62556
5 changed files with 286 additions and 392 deletions

View File

@ -1649,7 +1649,7 @@ a_Player:OpenWindow(Window);
]], ]],
Functions = 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." }, 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." }, 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!" }, 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." }, 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>" }, 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>" }, 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." }, Get = { Params = "", Return = "Root object", Notes = "(STATIC)This function returns the cRoot object." },
@ -2069,8 +2069,8 @@ end
Functions = Functions =
{ {
AddPlayerScore = { Params = "Name, Type, Value", Return = "", Notes = "Adds a value to all player scores of the specified objective type." }, 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." }, 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, [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." }, 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." }, GetNumObjectives = { Params = "", Return = "number", Notes = "Returns the nuber of registered objectives." },
GetNumTeams = { Params = "", Return = "number", Notes = "Returns the number of registered teams." }, GetNumTeams = { Params = "", Return = "number", Notes = "Returns the number of registered teams." },
GetObjective = { Params = "string", Return = "{{cObjective}}", Notes = "Returns the objective with the specified name." }, 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." }, 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." }, 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." }, 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." }, 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 = "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." }, 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 = "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." }, 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 = "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." }, 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 = "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." }, 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 = "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." }, 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 = "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." }, 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, [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." }, 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 = "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." }, 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 = "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." }, 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 = "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." }, 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, [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." }, 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, [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." }, 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 = 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!" }, { 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." }, 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." },
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", 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." },
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", 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." },
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", 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." },
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." },
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." }, 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." }, 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, [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." }, 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, [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." }, 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)." }, 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." }, 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 = GetBlock =

View File

@ -82,7 +82,7 @@ function Initialize(a_Plugin)
a_CBPlayer:GetWorld():DoWithEntityByID( -- This will crash the server in #1889 a_CBPlayer:GetWorld():DoWithEntityByID( -- This will crash the server in #1889
a_CBEntity:GetUniqueID(), a_CBEntity:GetUniqueID(),
function(Entity) function(Entity)
LOG("RightClicking an entity, crash #1889 fixed") LOG("RightClicking an entity, crash #1889 fixed. Entity is a " .. tolua.type(Entity))
end end
) )
end end

View File

@ -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) void cLuaState::GetStackValue(int a_StackPos, pPluginManager & a_ReturnedVal)
{ {
if (lua_isnil(m_LuaState, a_StackPos)) if (lua_isnil(m_LuaState, a_StackPos))

View File

@ -50,6 +50,7 @@ class cItems;
class cLuaServerHandle; class cLuaServerHandle;
class cLuaTCPLink; class cLuaTCPLink;
class cLuaUDPEndpoint; class cLuaUDPEndpoint;
class cMapManager;
class cMonster; class cMonster;
class cPickup; class cPickup;
class cPlayer; class cPlayer;
@ -68,6 +69,7 @@ struct HTTPTemplateRequest;
struct TakeDamageInfo; struct TakeDamageInfo;
typedef cBoundingBox * pBoundingBox; typedef cBoundingBox * pBoundingBox;
typedef cMapManager * pMapManager;
typedef cPluginManager * pPluginManager; typedef cPluginManager * pPluginManager;
typedef cRoot * pRoot; typedef cRoot * pRoot;
typedef cScoreboard * pScoreboard; typedef cScoreboard * pScoreboard;
@ -248,6 +250,7 @@ public:
void GetStackValue(int a_StackPos, eWeather & a_Value); void GetStackValue(int a_StackPos, eWeather & a_Value);
void GetStackValue(int a_StackPos, int & a_Value); void GetStackValue(int a_StackPos, int & a_Value);
void GetStackValue(int a_StackPos, pBoundingBox & 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, pPluginManager & a_Value);
void GetStackValue(int a_StackPos, pRoot & a_Value); void GetStackValue(int a_StackPos, pRoot & a_Value);
void GetStackValue(int a_StackPos, pScoreboard & a_Value); void GetStackValue(int a_StackPos, pScoreboard & a_Value);

View File

@ -627,87 +627,59 @@ static int tolua_StaticDoWith(lua_State * tolua_S)
template < template <
class Ty1, class Ty1,
class Ty2, 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' */ // Check params:
if ((NumArgs != 2) && (NumArgs != 3)) cLuaState L(tolua_S);
if (
!L.CheckParamNumber(2) ||
!L.CheckParamFunction(3)
)
{ {
return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 2 or 3 arguments, got %i", NumArgs); return 0;
} }
Ty1 * self = (Ty1 *)tolua_tousertype(tolua_S, 1, nullptr); // Get parameters:
Ty1 * Self = nullptr;
int ItemID = (int)tolua_tonumber(tolua_S, 2, 0); int ItemID;
if (!lua_isfunction(tolua_S, 3)) cLuaState::cRef FnRef;
L.GetStackValues(1, Self, ItemID, FnRef);
if (Self == nullptr)
{ {
return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a function for parameter #2", NumArgs); return lua_do_error(tolua_S, "Error in function call '#funcname#': Invalid 'self'");
} }
if (!FnRef.IsValid())
/* 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)
{ {
TableRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX); return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a valid callback function for parameter #2");
if (TableRef == LUA_REFNIL)
{
return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get value reference of parameter #3", NumArgs);
}
}
/* 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)
{
return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get function reference of parameter #2", NumArgs);
} }
class cLuaCallback : public cItemCallback<Ty2> class cLuaCallback : public cItemCallback<Ty2>
{ {
public: public:
cLuaCallback(lua_State * a_LuaState, int a_FuncRef, int a_TableRef) : cLuaCallback(cLuaState & a_LuaState, cLuaState::cRef & a_FnRef):
LuaState(a_LuaState), m_LuaState(a_LuaState),
FuncRef(a_FuncRef), m_FnRef(a_FnRef)
TableRef(a_TableRef)
{ {
} }
private: private:
virtual bool Item(Ty2 * a_Item) override virtual bool Item(Ty2 * a_Item) override
{ {
lua_rawgeti(LuaState, LUA_REGISTRYINDEX, FuncRef); // Push function to call bool ret = false;
tolua_pushusertype(LuaState, a_Item, a_Item->GetClass()); // Push the item m_LuaState.Call(m_FnRef, a_Item, cLuaState::Return, ret);
if (TableRef != LUA_REFNIL) return ret;
{
lua_rawgeti(LuaState, LUA_REGISTRYINDEX, TableRef); // Push the optional callbackdata param
} }
cLuaState & m_LuaState;
cLuaState::cRef & m_FnRef;
} Callback(L, FnRef);
int s = lua_pcall(LuaState, (TableRef == LUA_REFNIL ? 1 : 2), 1, 0); // Call the DoWith function:
if (cLuaState::ReportErrors(LuaState, s)) bool res = (Self->*DoWithFn)(ItemID, Callback);
{
return true; // Abort enumeration
}
if (lua_isboolean(LuaState, -1))
{
return (tolua_toboolean(LuaState, -1, 0) > 0);
}
return false; /* Continue enumeration */
}
lua_State * LuaState;
int FuncRef;
int TableRef;
} Callback(tolua_S, FuncRef, TableRef);
// Push the result as the return value:
bool bRetVal = (self->*Func1)(ItemID, Callback); L.Push(res);
/* 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);
/* Push return value on stack */
tolua_pushboolean(tolua_S, bRetVal);
return 1; return 1;
} }
@ -718,92 +690,59 @@ static int tolua_DoWithID(lua_State* tolua_S)
template < template <
class Ty1, class Ty1,
class Ty2, 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) static int tolua_DoWithXYZ(lua_State* tolua_S)
{ {
int NumArgs = lua_gettop(tolua_S) - 1; /* This includes 'self' */ // Check params:
if ((NumArgs != 4) && (NumArgs != 5)) cLuaState L(tolua_S);
if (
!L.CheckParamNumber(2, 5) ||
!L.CheckParamFunction(6)
)
{ {
return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 4 or 5 arguments, got %i", NumArgs); return 0;
} }
Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, nullptr); // Get parameters:
if (!lua_isnumber(tolua_S, 2) || !lua_isnumber(tolua_S, 3) || !lua_isnumber(tolua_S, 4)) Ty1 * Self = nullptr;
int BlockX, BlockY, BlockZ;
cLuaState::cRef FnRef;
L.GetStackValues(1, Self, BlockX, BlockY, BlockZ, FnRef);
if (Self == nullptr)
{ {
return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a number for parameters #1, #2 and #3"); return lua_do_error(tolua_S, "Error in function call '#funcname#': Invalid 'self'");
} }
if (!FnRef.IsValid())
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))
{ {
return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a function for parameter #4"); return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a valid callback function for parameter #5");
}
/* 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)
{
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");
}
}
/* 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)
{
return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get function reference of parameter #4");
} }
class cLuaCallback : public cItemCallback<Ty2> class cLuaCallback : public cItemCallback<Ty2>
{ {
public: public:
cLuaCallback(lua_State* a_LuaState, int a_FuncRef, int a_TableRef): cLuaCallback(cLuaState & a_LuaState, cLuaState::cRef & a_FnRef):
LuaState(a_LuaState), m_LuaState(a_LuaState),
FuncRef(a_FuncRef), m_FnRef(a_FnRef)
TableRef(a_TableRef)
{ {
} }
private: private:
virtual bool Item(Ty2 * a_Item) override virtual bool Item(Ty2 * a_Item) override
{ {
lua_rawgeti(LuaState, LUA_REGISTRYINDEX, FuncRef); /* Push function reference */ bool ret = false;
tolua_pushusertype(LuaState, a_Item, Ty2::GetClassStatic()); m_LuaState.Call(m_FnRef, a_Item, cLuaState::Return, ret);
if (TableRef != LUA_REFNIL) return ret;
{
lua_rawgeti(LuaState, LUA_REGISTRYINDEX, TableRef); /* Push table reference */
} }
cLuaState & m_LuaState;
cLuaState::cRef & m_FnRef;
} Callback(L, FnRef);
int s = lua_pcall(LuaState, (TableRef == LUA_REFNIL ? 1 : 2), 1, 0); // Call the DoWith function:
if (cLuaState::ReportErrors(LuaState, s)) bool res = (Self->*DoWithFn)(BlockX, BlockY, BlockZ, Callback);
{
return true; // Abort enumeration
}
if (lua_isboolean(LuaState, -1))
{
return (tolua_toboolean(LuaState, -1, 0) > 0);
}
return false; /* Continue enumeration */
}
lua_State * LuaState;
int FuncRef;
int TableRef;
} Callback(tolua_S, FuncRef, TableRef);
bool bRetVal = (self->*Func1)(ItemX, ItemY, ItemZ, Callback); // Push the result as the return value:
L.Push(res);
/* 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);
/* Push return value on stack */
tolua_pushboolean(tolua_S, bRetVal);
return 1; return 1;
} }
@ -814,93 +753,59 @@ static int tolua_DoWithXYZ(lua_State* tolua_S)
template < template <
class Ty1, class Ty1,
class Ty2, class Ty2,
bool (Ty1::*Func1)(int, int, cItemCallback<Ty2> &) bool (Ty1::*ForEachFn)(int, int, cItemCallback<Ty2> &)
> >
static int tolua_ForEachInChunk(lua_State * tolua_S) static int tolua_ForEachInChunk(lua_State * tolua_S)
{ {
int NumArgs = lua_gettop(tolua_S) - 1; /* This includes 'self' */ // Check params:
if ((NumArgs != 3) && (NumArgs != 4)) cLuaState L(tolua_S);
if (
!L.CheckParamNumber(2, 4) ||
!L.CheckParamFunction(5)
)
{ {
return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 3 or 4 arguments, got %i", NumArgs); return 0;
} }
Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, nullptr); // Get parameters:
if (!lua_isnumber(tolua_S, 2) || !lua_isnumber(tolua_S, 3)) Ty1 * Self = nullptr;
int ChunkX, ChunkZ;
cLuaState::cRef FnRef;
L.GetStackValues(1, Self, ChunkX, ChunkZ, FnRef);
if (Self == nullptr)
{ {
return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a number for parameters #1 and #2"); return lua_do_error(tolua_S, "Error in function call '#funcname#': Invalid 'self'");
} }
if (!FnRef.IsValid())
int ChunkX = ((int)tolua_tonumber(tolua_S, 2, 0));
int ChunkZ = ((int)tolua_tonumber(tolua_S, 3, 0));
if (!lua_isfunction(tolua_S, 4))
{ {
return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a function for parameter #3"); return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a valid callback function for parameter #4");
}
/* 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)
{
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");
}
}
/* 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)
{
return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get function reference of parameter #3");
} }
class cLuaCallback : public cItemCallback<Ty2> class cLuaCallback : public cItemCallback<Ty2>
{ {
public: public:
cLuaCallback(lua_State* a_LuaState, int a_FuncRef, int a_TableRef): cLuaCallback(cLuaState & a_LuaState, cLuaState::cRef & a_FnRef):
LuaState(a_LuaState), m_LuaState(a_LuaState),
FuncRef(a_FuncRef), m_FnRef(a_FnRef)
TableRef(a_TableRef)
{ {
} }
private: private:
virtual bool Item(Ty2 * a_Item) override virtual bool Item(Ty2 * a_Item) override
{ {
lua_rawgeti(LuaState, LUA_REGISTRYINDEX, FuncRef); /* Push function reference */ bool ret = false;
tolua_pushusertype(LuaState, a_Item, Ty2::GetClassStatic()); m_LuaState.Call(m_FnRef, a_Item, cLuaState::Return, ret);
if (TableRef != LUA_REFNIL) return ret;
{
lua_rawgeti(LuaState, LUA_REGISTRYINDEX, TableRef); /* Push table reference */
} }
cLuaState & m_LuaState;
cLuaState::cRef & m_FnRef;
} Callback(L, FnRef);
int s = lua_pcall(LuaState, (TableRef == LUA_REFNIL ? 1 : 2), 1, 0); // Call the DoWith function:
if (cLuaState::ReportErrors(LuaState, s)) bool res = (Self->*ForEachFn)(ChunkX, ChunkZ, Callback);
{
return true; /* Abort enumeration */
}
if (lua_isboolean(LuaState, -1)) // Push the result as the return value:
{ L.Push(res);
return (tolua_toboolean(LuaState, -1, 0) > 0);
}
return false; /* Continue enumeration */
}
lua_State * LuaState;
int FuncRef;
int TableRef;
} Callback(tolua_S, FuncRef, TableRef);
bool bRetVal = (self->*Func1)(ChunkX, ChunkZ, Callback);
/* 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);
/* Push return value on stack */
tolua_pushboolean(tolua_S, bRetVal);
return 1; return 1;
} }
@ -911,7 +816,7 @@ static int tolua_ForEachInChunk(lua_State * tolua_S)
template < template <
class Ty1, class Ty1,
class Ty2, class Ty2,
bool (Ty1::*Func1)(const cBoundingBox &, cItemCallback<Ty2> &) bool (Ty1::*ForEachFn)(const cBoundingBox &, cItemCallback<Ty2> &)
> >
static int tolua_ForEachInBox(lua_State * tolua_S) static int tolua_ForEachInBox(lua_State * tolua_S)
{ {
@ -930,16 +835,18 @@ static int tolua_ForEachInBox(lua_State * tolua_S)
// Get the params: // Get the params:
Ty1 * Self = nullptr; Ty1 * Self = nullptr;
cBoundingBox * Box = nullptr; cBoundingBox * Box = nullptr;
L.GetStackValues(1, Self, Box); cLuaState::cRef FnRef;
L.GetStackValues(1, Self, Box, FnRef);
if ((Self == nullptr) || (Box == nullptr)) if ((Self == nullptr) || (Box == nullptr))
{ {
LOGWARNING("Invalid world (%p) or boundingbox (%p)", Self, Box); LOGWARNING("Invalid world (%p) or boundingbox (%p)", Self, Box);
L.LogStackTrace(); L.LogStackTrace();
return 0; return 0;
} }
if (!FnRef.IsValid())
// Create a reference for the function: {
cLuaState::cRef FnRef(L, 3); 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: // Callback wrapper for the Lua function:
class cLuaCallback : public cItemCallback<Ty2> class cLuaCallback : public cItemCallback<Ty2>
@ -970,12 +877,10 @@ static int tolua_ForEachInBox(lua_State * tolua_S)
} }
} Callback(L, FnRef); } Callback(L, FnRef);
bool bRetVal = (Self->*Func1)(*Box, Callback); bool res = (Self->*ForEachFn)(*Box, Callback);
FnRef.UnRef(); // Push the result as the return value:
L.Push(res);
/* Push return value on stack */
tolua_pushboolean(tolua_S, bRetVal);
return 1; return 1;
} }
@ -986,7 +891,7 @@ static int tolua_ForEachInBox(lua_State * tolua_S)
template < template <
class Ty1, class Ty1,
class Ty2, class Ty2,
bool (Ty1::*Func1)(cItemCallback<Ty2> &) bool (Ty1::*ForEachFn)(cItemCallback<Ty2> &)
> >
static int tolua_ForEach(lua_State * tolua_S) static int tolua_ForEach(lua_State * tolua_S)
{ {
@ -1001,13 +906,17 @@ static int tolua_ForEach(lua_State * tolua_S)
} }
// Get the params: // Get the params:
Ty1 * self; Ty1 * Self = nullptr;
L.GetStackValues(1, self); cLuaState::cRef FnRef;
cLuaState::cRef FnRef(L, 2); L.GetStackValues(1, Self, FnRef);
if (self == nullptr) if (Self == nullptr)
{ {
return lua_do_error(tolua_S, "Error in function call '#funcname#': Invalid 'self'."); 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> class cLuaCallback : public cItemCallback<Ty2>
{ {
@ -1031,7 +940,7 @@ static int tolua_ForEach(lua_State * tolua_S)
} Callback(L, FnRef); } Callback(L, FnRef);
// Call the enumeration: // Call the enumeration:
bool res = (self->*Func1)(Callback); bool res = (Self->*ForEachFn)(Callback);
// Push the return value: // Push the return value:
L.Push(res); L.Push(res);
@ -1046,7 +955,7 @@ static int tolua_ForEach(lua_State * tolua_S)
template < template <
class Ty1, class Ty1,
class Ty2, class Ty2,
bool (Ty1::*Func1)(cItemCallback<Ty2> &) bool (Ty1::*ForEachFn)(cItemCallback<Ty2> &)
> >
static int tolua_StaticForEach(lua_State * tolua_S) static int tolua_StaticForEach(lua_State * tolua_S)
{ {
@ -1062,6 +971,10 @@ static int tolua_StaticForEach(lua_State * tolua_S)
// Get the params: // Get the params:
cLuaState::cRef FnRef(L, 2); 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> class cLuaCallback : public cItemCallback<Ty2>
{ {
@ -1085,7 +998,7 @@ static int tolua_StaticForEach(lua_State * tolua_S)
} Callback(L, FnRef); } Callback(L, FnRef);
// Call the enumeration: // Call the enumeration:
bool res = (Ty1::Get()->*Func1)(Callback); bool res = (Ty1::Get()->*ForEachFn)(Callback);
// Push the return value: // Push the return value:
L.Push(res); 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) // Exported manually, because tolua would generate useless additional parameters (a_BlockType .. a_BlockSkyLight)
// Function signature: GetBlockInfo(BlockX, BlockY, BlockZ) -> BlockValid, [BlockType, BlockMeta, BlockSkyLight, BlockBlockLight] // 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 ( if (
!tolua_isusertype (tolua_S, 1, "cWorld", 0, &tolua_err) || !L.CheckParamUserType(1, "cWorld") ||
!tolua_isnumber (tolua_S, 2, 0, &tolua_err) || !L.CheckParamNumber(2, 4) ||
!tolua_isnumber (tolua_S, 3, 0, &tolua_err) || !L.CheckParamEnd(5)
!tolua_isnumber (tolua_S, 4, 0, &tolua_err) ||
!tolua_isnoobj (tolua_S, 5, &tolua_err)
) )
goto tolua_lerror;
else
#endif
{ {
cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, nullptr); return 0;
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
// 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; BLOCKTYPE BlockType;
NIBBLETYPE BlockMeta, BlockSkyLight, BlockBlockLight; NIBBLETYPE BlockMeta, BlockSkyLight, BlockBlockLight;
bool res = self->GetBlockInfo(BlockX, BlockY, BlockZ, BlockType, BlockMeta, BlockSkyLight, BlockBlockLight); bool res = Self->GetBlockInfo(BlockX, BlockY, BlockZ, BlockType, BlockMeta, BlockSkyLight, BlockBlockLight);
tolua_pushboolean(tolua_S, res ? 1 : 0);
// Push the returned values:
L.Push(res);
if (res) if (res)
{ {
tolua_pushnumber(tolua_S, BlockType); L.Push(BlockType);
tolua_pushnumber(tolua_S, BlockMeta); L.Push(BlockMeta);
tolua_pushnumber(tolua_S, BlockSkyLight); L.Push(BlockSkyLight);
tolua_pushnumber(tolua_S, BlockBlockLight); L.Push(BlockBlockLight);
return 5; return 5;
} }
}
}
return 1; 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) // Exported manually, because tolua would generate useless additional parameters (a_BlockType, a_BlockMeta)
// Function signature: GetBlockTypeMeta(BlockX, BlockY, BlockZ) -> BlockValid, [BlockType, BlockMeta] // Function signature: GetBlockTypeMeta(BlockX, BlockY, BlockZ) -> BlockValid, [BlockType, BlockMeta]
#ifndef TOLUA_RELEASE
tolua_Error tolua_err; // Check params:
cLuaState L(tolua_S);
if ( if (
!tolua_isusertype (tolua_S, 1, "cWorld", 0, &tolua_err) || !L.CheckParamUserType(1, "cWorld") ||
!tolua_isnumber (tolua_S, 2, 0, &tolua_err) || !L.CheckParamNumber(2, 4) ||
!tolua_isnumber (tolua_S, 3, 0, &tolua_err) || !L.CheckParamEnd(5)
!tolua_isnumber (tolua_S, 4, 0, &tolua_err) ||
!tolua_isnoobj (tolua_S, 5, &tolua_err)
) )
goto tolua_lerror;
else
#endif
{ {
cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, nullptr); return 0;
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
// 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; BLOCKTYPE BlockType;
NIBBLETYPE BlockMeta; NIBBLETYPE BlockMeta;
bool res = self->GetBlockTypeMeta(BlockX, BlockY, BlockZ, BlockType, BlockMeta); bool res = Self->GetBlockTypeMeta(BlockX, BlockY, BlockZ, BlockType, BlockMeta);
tolua_pushboolean(tolua_S, res ? 1 : 0);
// Push the returned values:
L.Push(res);
if (res) if (res)
{ {
tolua_pushnumber(tolua_S, BlockType); L.Push(BlockType);
tolua_pushnumber(tolua_S, BlockMeta); L.Push(BlockMeta);
return 3; return 3;
} }
}
}
return 1; 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) static int tolua_cWorld_GetSignLines(lua_State * tolua_S)
{ {
// Exported manually, because tolua would generate useless additional parameters (a_Line1 .. a_Line4) // 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 ( if (
!tolua_isusertype (tolua_S, 1, "cWorld", 0, &tolua_err) || !L.CheckParamUserType(1, "cWorld") ||
!tolua_isnumber (tolua_S, 2, 0, &tolua_err) || !L.CheckParamNumber(2, 4) ||
!tolua_isnumber (tolua_S, 3, 0, &tolua_err) || !L.CheckParamEnd(5)
!tolua_isnumber (tolua_S, 4, 0, &tolua_err) ||
!tolua_isnoobj (tolua_S, 10, &tolua_err)
) )
goto tolua_lerror;
else
#endif
{ {
cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, nullptr); return 0;
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
// 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; AString Line1, Line2, Line3, Line4;
bool res = self->GetSignLines(BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4); bool res = Self->GetSignLines(BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4);
tolua_pushboolean(tolua_S, res ? 1 : 0);
// Push the returned values:
L.Push(res);
if (res) if (res)
{ {
tolua_pushstring(tolua_S, Line1.c_str()); L.Push(Line1);
tolua_pushstring(tolua_S, Line2.c_str()); L.Push(Line2);
tolua_pushstring(tolua_S, Line3.c_str()); L.Push(Line3);
tolua_pushstring(tolua_S, Line4.c_str()); L.Push(Line4);
return 5; return 5;
} }
}
}
return 1; 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) static int tolua_cWorld_SetSignLines(lua_State * tolua_S)
{ {
// Exported manually, because tolua would generate useless additional return values (a_Line1 .. a_Line4) // Exported manually, because tolua would generate useless additional return values (a_Line1 .. a_Line4)
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
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
{
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 1;
#ifndef TOLUA_RELEASE // Check params:
tolua_lerror: cLuaState L(tolua_S);
tolua_error(tolua_S, "#ferror in function 'SetSignLines'.", &tolua_err); if (
!L.CheckParamUserType(1, "cWorld") ||
!L.CheckParamNumber(2, 4) ||
!L.CheckParamString(5, 8) ||
!L.CheckParamEnd(9)
)
{
return 0; return 0;
#endif }
// 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;
} }