Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
basic_robot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
basic_robot
Commits
d177e3c3
Commit
d177e3c3
authored
8 years ago
by
rnd1
Browse files
Options
Downloads
Patches
Plain Diff
infinite loop/recursion prevention:
replaced expensive function calls with "if"
parent
6c82554a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
init.lua
+13
-12
13 additions, 12 deletions
init.lua
with
13 additions
and
12 deletions
init.lua
+
13
−
12
View file @
d177e3c3
...
...
@@ -3,7 +3,7 @@
basic_robot
=
{};
---- SETTINGS ------
basic_robot
.
call_limit
=
32
;
-- how many execution calls per script run allowed
basic_robot
.
call_limit
=
48
;
-- how many execution calls per script run allowed
basic_robot
.
bad_inventory_blocks
=
{
-- disallow taking from these nodes inventories
[
"craft_guide:sign_wall"
]
=
true
,
...
...
@@ -389,7 +389,7 @@ function getSandboxEnv (name)
error
=
error
,
debug
=
debug
,
_ccounter
=
basic_robot.data[name].ccounter
,
--
counts
how
many
executions
of
critical
spots
in
script
--
_ccounter
=
basic_robot.data[name].ccounter
,
--
counts
how
many
executions
of
critical
spots
in
script
increase_ccounter
=
function
()
...
...
@@ -465,12 +465,13 @@ local function preprocess_code(script)
when counter exceeds limit exit with error
--]]
script
=
"_ccounter = 0; "
..
script
;
local
i1
-- process script to insert call counter in every function
local
insert_code
=
" increase_ccounter(); "
;
local
_increase_ccounter
=
" if _ccounter > "
..
basic_robot
.
call_limit
..
" then error(\"
Execution
count
\
".. _ccounter .. \"
exceeded
".. basic_robot.call_limit .. "
\
") end _ccounter = _ccounter + 1; "
local
i1
=
0
;
local
i2
=
0
;
local
found
=
true
;
...
...
@@ -486,7 +487,7 @@ local function preprocess_code(script)
local
i21
=
i2
;
i2
=
string.find
(
script
,
"do"
,
i2
);
if
i2
then
script
=
script
.
sub
(
script
,
1
,
i2
+
1
)
..
in
sert_code
..
script
.
sub
(
script
,
i2
+
2
);
script
=
script
.
sub
(
script
,
1
,
i2
+
1
)
..
_
in
crease_ccounter
..
script
.
sub
(
script
,
i2
+
2
);
i1
=
i21
+
6
;
-- after while
found
=
true
;
end
...
...
@@ -499,8 +500,8 @@ local function preprocess_code(script)
if
not
is_inside_string
(
i2
,
script
)
then
i2
=
string.find
(
script
,
")"
,
i2
);
if
i2
then
script
=
script
.
sub
(
script
,
1
,
i2
)
..
in
sert_code
..
script
.
sub
(
script
,
i2
+
1
);
i1
=
i2
+
string.len
(
in
sert_code
);
script
=
script
.
sub
(
script
,
1
,
i2
)
..
_
in
crease_ccounter
..
script
.
sub
(
script
,
i2
+
1
);
i1
=
i2
+
string.len
(
_
in
crease_ccounter
);
found
=
true
;
end
end
...
...
@@ -512,8 +513,8 @@ local function preprocess_code(script)
if
not
is_inside_string
(
i2
,
script
)
then
i2
=
string.find
(
script
,
"do "
,
i2
);
if
i2
then
script
=
script
.
sub
(
script
,
1
,
i2
+
1
)
..
in
sert_code
..
script
.
sub
(
script
,
i2
+
2
);
i1
=
i2
+
string.len
(
in
sert_code
);
script
=
script
.
sub
(
script
,
1
,
i2
+
1
)
..
_
in
crease_ccounter
..
script
.
sub
(
script
,
i2
+
2
);
i1
=
i2
+
string.len
(
_
in
crease_ccounter
);
found
=
true
;
end
end
...
...
@@ -522,8 +523,8 @@ local function preprocess_code(script)
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
)
..
in
sert_code
..
script
.
sub
(
script
,
i2
);
i1
=
i2
+
string.len
(
in
sert_code
)
+
5
;
-- insert + skip goto
script
=
script
.
sub
(
script
,
1
,
i2
-
1
)
..
_
in
crease_ccounter
..
script
.
sub
(
script
,
i2
);
i1
=
i2
+
string.len
(
_
in
crease_ccounter
)
+
5
;
-- insert + skip goto
found
=
true
;
end
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment