update console commands execution pipeline
This commit is contained in:
parent
a0210c82ce
commit
db2795eb4f
@ -2,6 +2,13 @@
|
|||||||
|
|
||||||
To work with the command interpreter, use the **console** library.
|
To work with the command interpreter, use the **console** library.
|
||||||
|
|
||||||
|
When sending a command via the standard console (core:console layout):
|
||||||
|
1. the `allow-cheats` rule is checked
|
||||||
|
2. the `pos.x|y|z`, `entity.id`, `entity.selected` variables are automatically set.
|
||||||
|
3. the command handler is called - console.submit or the default one.
|
||||||
|
|
||||||
|
The default handler calls console.execute, passing the result to the console.log call.
|
||||||
|
|
||||||
## Commands creation
|
## Commands creation
|
||||||
|
|
||||||
To create a console command, use the following function:
|
To create a console command, use the following function:
|
||||||
|
|||||||
@ -2,6 +2,13 @@
|
|||||||
|
|
||||||
Для работы с командным интерпретатором предоставляется библиотека **console**.
|
Для работы с командным интерпретатором предоставляется библиотека **console**.
|
||||||
|
|
||||||
|
При отправке команды через стандартную консоль (макет core:console):
|
||||||
|
1. проверяется правило `allow-cheats`
|
||||||
|
2. автоматически устанавливаются переменные `pos.x|y|z`, `entity.id`, `entity.selected`.
|
||||||
|
3. вызывается обработчик команд - console.submit или по-умолчанию.
|
||||||
|
|
||||||
|
Обработчик по-умолчанию вызывает console.execute, передавая результат в вызов console.log.
|
||||||
|
|
||||||
## Создание команд
|
## Создание команд
|
||||||
|
|
||||||
Для создания команды консоли используется следующая функция:
|
Для создания команды консоли используется следующая функция:
|
||||||
|
|||||||
@ -101,7 +101,7 @@ function setup_variables()
|
|||||||
console.set('pos.y', y)
|
console.set('pos.y', y)
|
||||||
console.set('pos.z', z)
|
console.set('pos.z', z)
|
||||||
local pentity = player.get_entity(pid)
|
local pentity = player.get_entity(pid)
|
||||||
if pentity ~= 0 then
|
if pentity > 0 then
|
||||||
console.set('entity.id', pentity)
|
console.set('entity.id', pentity)
|
||||||
end
|
end
|
||||||
local sentity = player.get_selected_entity(pid)
|
local sentity = player.get_selected_entity(pid)
|
||||||
@ -148,8 +148,6 @@ function submit(text)
|
|||||||
text = text:sub(2)
|
text = text:sub(2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
setup_variables()
|
|
||||||
|
|
||||||
local name
|
local name
|
||||||
for s in text:gmatch("%S+") do
|
for s in text:gmatch("%S+") do
|
||||||
@ -167,12 +165,19 @@ function submit(text)
|
|||||||
end
|
end
|
||||||
|
|
||||||
document.log.caret = -1
|
document.log.caret = -1
|
||||||
local status, result = pcall(console.execute, text)
|
|
||||||
if result then
|
|
||||||
console.log(result)
|
|
||||||
end
|
|
||||||
document.prompt.text = ""
|
document.prompt.text = ""
|
||||||
document.prompt.focused = true
|
document.prompt.focused = true
|
||||||
|
|
||||||
|
setup_variables()
|
||||||
|
|
||||||
|
if console.submit then
|
||||||
|
console.submit(text)
|
||||||
|
else
|
||||||
|
local status, result = pcall(console.execute, text)
|
||||||
|
if result then
|
||||||
|
console.log(result)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function set_mode(mode)
|
function set_mode(mode)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user