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
7767b89f
Commit
7767b89f
authored
6 years ago
by
rnd
Browse files
Options
Downloads
Patches
Plain Diff
coroutine mode added and command pause(), start program with '--coroutine' to use it
parent
1225ca7e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
init.lua
+24
-4
24 additions, 4 deletions
init.lua
with
24 additions
and
4 deletions
init.lua
+
24
−
4
View file @
7767b89f
...
...
@@ -7,8 +7,7 @@ basic_robot.call_limit = 48; -- how many execution calls per script run allowed
basic_robot
.
entry_count
=
2
-- how many robots ordinary player can have
basic_robot
.
advanced_count
=
16
-- how many robots player with robot privs can have
basic_robot
.
radius
=
32
;
-- divide whole world into blocks of this size - used for managing events like keyboard punches
basic_robot
.
password
=
"randompassword"
;
-- IMPORTANT: change it before running mod, password used for authentifications
basic_robot
.
password
=
"raN___dOM_ p4S"
;
-- IMPORTANT: change it before running mod, password used for authentifications
basic_robot
.
bad_inventory_blocks
=
{
-- disallow taking from these nodes inventories to prevent player abuses
[
"craft_guide:sign_wall"
]
=
true
,
...
...
@@ -19,7 +18,7 @@ basic_robot.dig_require_energy = true; -- does robot require energy to dig?
basic_robot
.
http_api
=
minetest
.
request_http_api
();
basic_robot
.
version
=
"2018/06/2
8
a"
;
basic_robot
.
version
=
"2018/06/2
9
a"
;
basic_robot
.
data
=
{};
-- stores all robot related data
--[[
...
...
@@ -80,6 +79,11 @@ function getSandboxEnv (name)
return
commands
.
craft
(
item
,
mode
,
idx
,
name
)
end
,
pause
=
function
()
-- pause coroutine
if
not
basic_robot
.
data
[
name
].
cor
then
error
(
"you must start program with '--coroutine' to use pause()"
)
return
end
coroutine.yield
()
end
,
self
=
{
pos
=
function
()
return
basic_robot
.
data
[
name
].
obj
:
getpos
()
end
,
spawnpos
=
function
()
local
pos
=
basic_robot
.
data
[
name
].
spawnpos
;
return
{
x
=
pos
.
x
,
y
=
pos
.
y
,
z
=
pos
.
z
}
end
,
...
...
@@ -680,8 +684,10 @@ local function initSandbox (name)
end
local
function
setCode
(
name
,
script
)
-- to run script: 1. initSandbox 2. setCode 3. runSandbox
local
err
;
local
cor
=
false
;
if
string.sub
(
script
,
1
,
11
)
==
"--coroutine"
then
cor
=
true
end
if
basic_robot
.
data
[
name
].
authlevel
<
3
then
-- not admin
err
=
check_code
(
script
);
script
=
preprocess_code
(
script
);
...
...
@@ -691,6 +697,12 @@ local function setCode( name, script ) -- to run script: 1. initSandbox 2. setCo
local
bytecode
,
err
=
CompileCode
(
script
);
if
err
then
return
err
end
basic_robot
.
data
[
name
].
bytecode
=
bytecode
;
if
cor
then
-- create coroutine if requested
basic_robot
.
data
[
name
].
cor
=
coroutine.create
(
bytecode
)
else
basic_robot
.
data
[
name
].
cor
=
nil
end
return
nil
end
...
...
@@ -709,6 +721,14 @@ local function runSandbox( name)
setfenv
(
ScriptFunc
,
data
.
sandbox
)
cor
=
basic_robot
.
data
[
name
].
cor
;
if
cor
then
-- coroutine!
local
err
,
ret
err
,
ret
=
coroutine.resume
(
cor
)
if
err
then
return
err
end
return
nil
end
local
Result
,
RuntimeError
=
pcall
(
ScriptFunc
)
if
RuntimeError
then
return
RuntimeError
...
...
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