Skip to content
Snippets Groups Projects
Commit 905d7025 authored by rnd1's avatar rnd1
Browse files

fixes

parent e75ba494
No related branches found
No related tags found
No related merge requests found
......@@ -164,14 +164,15 @@ basic_robot.commands.take_item = function(name,item, inventory,dir)
if not inventory then inventory = "main"; end
--if not inv then return end
local stack = ItemStack(item);
if (not tinv:contains_item(inventory, stack) or not inv:room_for_item("main", stack)) and meta:get_int("admin")~=1 then
local contains = tinv:contains_item(inventory, stack);
if (not contains or not inv:room_for_item("main", stack)) and meta:get_int("admin")~=1 then
return false
end
inv:add_item("main",stack);
tinv:remove_item(inventory, stack);
return true
return contains
end
......
......@@ -341,7 +341,7 @@ end
local function check_code(code)
--"while ", "for ", "do ","goto ",
local bad_code = {"repeat ", "until ", "_ccounter", "_G", "while%(", "while{", "pcall"}
local bad_code = {"repeat ", "until ", "_ccounter", "_G", "while%(", "while{", "pcall","\\\""}
for _, v in pairs(bad_code) do
if string.find(code, v) then
......@@ -392,54 +392,64 @@ local function CompileCode ( script )
local i1 -- process script to insert call counter in every function
local insert_code = " increase_ccounter(); ";
local i1=0; local i2 = 0;
local i1=0; local i2 = 0;
local found = true;
while (i2) do -- PROCESS SCRIPT AND INSERT COUNTER AT PROBLEMATIC SPOTS
i2 = nil;
i2=string.find (script, "function", i1) -- fix functions
while (found) do -- PROCESS SCRIPT AND INSERT COUNTER AT PROBLEMATIC SPOTS
found = false;
i2 = nil;
i2=string.find (script, "while ", i1) -- fix while OK
if i2 then
--minetest.chat_send_all("while0");
if not is_inside_string(i2,script) then
i2=string.find(script, ")", i2);
local i21 = i2;
i2=string.find(script, "do ", i2);
if i2 then
script = script.sub(script,1, i2) .. insert_code .. script.sub(script, i2+1);
i1=i2+string.len(insert_code);
script = script.sub(script,1, i2+1) .. insert_code .. script.sub(script, i2+2);
i1=i21+6; -- after while
found = true;
end
end
end
i2=string.find (script, "for ", i1) -- fix for OK
i2=string.find (script, "function", i1) -- fix functions
if i2 then
--minetest.chat_send_all("func0")
if not is_inside_string(i2,script) then
i2=string.find(script, "do ", i2);
i2=string.find(script, ")", i2);
if i2 then
script = script.sub(script,1, i2+1) .. insert_code .. script.sub(script, i2+2);
script = script.sub(script,1, i2) .. insert_code .. script.sub(script, i2+1);
i1=i2+string.len(insert_code);
found = true;
end
end
end
i2=string.find (script, "while ", i1) -- fix while OK
i2=string.find (script, "for ", i1) -- fix for OK
if i2 then
if not is_inside_string(i2,script) then
i2=string.find(script, "do ", i2);
if i2 then
script = script.sub(script,1, i2+1) .. insert_code .. script.sub(script, i2+2);
i1=i2+string.len(insert_code);
found = true;
end
end
end
i2=string.find (script, "goto ", i1) -- fix goto OK
if i2 then
if not is_inside_string(i2,script) then
script = script.sub(script,1, i2-1) .. insert_code .. script.sub(script, i2);
i1=i2+string.len(insert_code)+5; -- insert + skip goto
found = true;
end
end
--minetest.chat_send_all("code rem " .. string.sub(script,i1))
end
......@@ -490,15 +500,7 @@ local function runSandbox( name)
return nil
end
-- note: to see memory used by lua in kbytes: collectgarbage("count")
-- /spawnentity basic_robot:robot
-- TODO.. display form when right click robot
local function update_formspec_robot(self)
end
local robot_spawner_update_form = function (pos, mode)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment