1
0

Debuggers: sorted things into separate functions, commented out most of them; added ForEachEntity() testing - list all and kill all entities.

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1492 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2013-05-19 15:45:03 +00:00
parent e32cffbbdd
commit 8311ee5ec6

View File

@ -17,46 +17,71 @@ function Initialize(Plugin)
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_USING_ITEM); PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_USING_ITEM);
PluginManager:AddHook(Plugin, cPluginManager.HOOK_TAKE_DAMAGE); PluginManager:AddHook(Plugin, cPluginManager.HOOK_TAKE_DAMAGE);
PluginManager:BindCommand("/le", "debuggers", HandleListEntitiesCmd, " - Shows a list of all the loaded entities");
PluginManager:BindCommand("/ke", "debuggers", HandleKillEntitiesCmd, " - Kills all the loaded entities");
-- Enable the following line for BlockArea / Generator interface testing: -- Enable the following line for BlockArea / Generator interface testing:
-- PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_GENERATED); -- PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_GENERATED);
LOG("Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion()) LOG("Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion())
-- dump all available functions to console: -- dump all available API functions and objects:
if (ShouldDumpFunctions) then if (ShouldDumpFunctions) then
LOG("Dumping all available functions:"); DumpAPI();
function dump (prefix, a, Output) end
for i, v in pairs (a) do
if (type(v) == "table") then
if (GetChar(i, 1) ~= ".") then -- TestBlockAreas();
if (v == _G) then -- TestSQLiteBindings();
LOG(prefix .. i .. " == _G, CYCLE, ignoring"); -- TestExpatBindings();
elseif (v == _G.package) then
LOG(prefix .. i .. " == _G.package, ignoring"); return true
else end;
dump(prefix .. i .. ".", v, Output)
end
end
elseif (type(v) == "function") then
if (string.sub(i, 1, 2) ~= "__") then
table.insert(Output, prefix .. i .. "()"); function DumpAPI()
LOG("Dumping all available functions to API.txt...");
function dump (prefix, a, Output)
for i, v in pairs (a) do
if (type(v) == "table") then
if (GetChar(i, 1) ~= ".") then
if (v == _G) then
LOG(prefix .. i .. " == _G, CYCLE, ignoring");
elseif (v == _G.package) then
LOG(prefix .. i .. " == _G.package, ignoring");
else
dump(prefix .. i .. ".", v, Output)
end end
end end
elseif (type(v) == "function") then
if (string.sub(i, 1, 2) ~= "__") then
table.insert(Output, prefix .. i .. "()");
end
end end
end end
local Output = {};
dump("", _G, Output);
table.sort(Output);
local f = io.open("API.txt", "w");
for i, n in ipairs(Output) do
f:write(n, "\n");
end
f:close();
LOG("API.txt written.");
end end
local Output = {};
dump("", _G, Output);
table.sort(Output);
local f = io.open("API.txt", "w");
for i, n in ipairs(Output) do
f:write(n, "\n");
end
f:close();
LOG("API.txt written.");
end
function TestBlockAreas()
LOG("Testing block areas...");
-- Debug block area merging: -- Debug block area merging:
local BA1 = cBlockArea(); local BA1 = cBlockArea();
@ -138,6 +163,16 @@ function Initialize(Plugin)
BA1:SaveToSchematicFile("schematics/ltm_YZ2.schematic"); BA1:SaveToSchematicFile("schematics/ltm_YZ2.schematic");
end end
LOG("Block areas test ended");
end
function TestSQLiteBindings()
LOG("Testing SQLite bindings...");
-- Debug SQLite binding -- Debug SQLite binding
local TestDB, ErrCode, ErrMsg = sqlite3.open("test.sqlite"); local TestDB, ErrCode, ErrMsg = sqlite3.open("test.sqlite");
@ -168,8 +203,17 @@ function Initialize(Plugin)
LOG("SQLite3 failed to open DB! (" .. ErrCode .. ", " .. ErrMsg ..")"); LOG("SQLite3 failed to open DB! (" .. ErrCode .. ", " .. ErrMsg ..")");
end end
LOG("SQLite bindings test ended");
end
-- Debug LuaExpat binding:
function TestExpatBindings()
LOG("Testing Expat bindings...");
-- Debug LuaExpat bindings:
local count = 0 local count = 0
callbacks = { callbacks = {
StartElement = function (parser, name) StartElement = function (parser, name)
@ -189,11 +233,10 @@ function Initialize(Plugin)
p:parse("more text"); p:parse("more text");
p:parse("</elem1>"); p:parse("</elem1>");
p:parse("\n"); p:parse("\n");
p:parse() -- finishes the document p:parse(); -- finishes the document
p:close() -- closes the parser p:close(); -- closes the parser
LOG("Expat bindings test ended");
return true
end end
@ -355,3 +398,57 @@ end
-- Function "round" copied from http://lua-users.org/wiki/SimpleRound
function round(num, idp)
local mult = 10^(idp or 0)
if num >= 0 then return math.floor(num * mult + 0.5) / mult
else return math.ceil(num * mult - 0.5) / mult end
end
function HandleListEntitiesCmd(Split, Player)
local NumEntities = 0;
local ListEntity = function(Entity)
if (Entity:IsDestroyed()) then
-- The entity has already been destroyed, don't list it
return false;
end;
Player:SendMessage(" " .. Entity:GetUniqueID() .. ": " .. Entity:GetClass() .. " {" .. round(Entity:GetPosX(), 2) .. ", " .. round(Entity:GetPosY(), 2) .. ", " .. round(Entity:GetPosZ(), 2) .."}");
NumEntities = NumEntities + 1;
end
Player:SendMessage("Listing all entities...");
Player:GetWorld():ForEachEntity(ListEntity);
Player:SendMessage("List finished, " .. NumEntities .. " entities listed");
return true;
end
function HandleKillEntitiesCmd(Split, Player)
local NumEntities = 0;
local KillEntity = function(Entity)
-- kill everything except for players:
if (Entity:GetEntityType() ~= cEntity.etPlayer) then
Entity:Destroy();
NumEntities = NumEntities + 1;
end;
end
Player:SendMessage("Killing all entities...");
Player:GetWorld():ForEachEntity(KillEntity);
Player:SendMessage("Killed " .. NumEntities .. " entities.");
return true;
end