summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/config/config.lua30
-rw-r--r--script/gc.lua2
-rw-r--r--script/proto/proto.lua26
-rw-r--r--script/timer.lua7
-rw-r--r--script/workspace/workspace.lua1
5 files changed, 38 insertions, 28 deletions
diff --git a/script/config/config.lua b/script/config/config.lua
index f72f5e57..c4ab69dc 100644
--- a/script/config/config.lua
+++ b/script/config/config.lua
@@ -234,8 +234,8 @@ m.nullSymbols = {
---@param nowValue any
---@param rawValue any
local function update(scp, key, nowValue, rawValue)
- local now = scp:get 'config.now'
- local raw = scp:get 'config.raw'
+ local now = m.getNowTable(scp)
+ local raw = m.getRawTable(scp)
now[key] = nowValue
raw[key] = rawValue
@@ -245,7 +245,7 @@ end
---@param key? string
---@return scope
local function getScope(uri, key)
- local raw = scope.override:get 'config.raw'
+ local raw = m.getRawTable(scope.override)
if raw then
if not key or raw[key] ~= nil then
return scope.override
@@ -256,7 +256,7 @@ local function getScope(uri, key)
local scp = scope.getFolder(uri) or scope.getLinkedScope(uri)
if scp then
if not key
- or (scp:get 'config.raw' and scp:get 'config.raw' [key] ~= nil) then
+ or m.getRawTable(scp)[key] ~= nil then
return scp
end
end
@@ -272,7 +272,7 @@ function m.setByScope(scp, key, value)
if not unit then
return false
end
- local raw = scp:get 'config.raw'
+ local raw = m.getRawTable(scp)
if util.equal(raw[key], value) then
return false
end
@@ -358,7 +358,7 @@ end
---@return any
function m.get(uri, key)
local scp = getScope(uri, key)
- local value = scp:get 'config.now' [key]
+ local value = m.getNowTable(scp)[key]
if value == nil then
value = Template[key].default
end
@@ -373,7 +373,7 @@ end
---@return any
function m.getRaw(uri, key)
local scp = getScope(uri, key)
- local value = scp:get 'config.raw' [key]
+ local value = m.getRawTable(scp)[key]
if value == nil then
value = Template[key].default
end
@@ -384,9 +384,21 @@ function m.getRaw(uri, key)
end
---@param scp scope
+function m.getNowTable(scp)
+ return scp:get 'config.now'
+ or scp:set('config.now', {})
+end
+
+---@param scp scope
+function m.getRawTable(scp)
+ return scp:get 'config.raw'
+ or scp:set('config.raw', {})
+end
+
+---@param scp scope
---@param ... table
function m.update(scp, ...)
- local oldConfig = scp:get 'config.now'
+ local oldConfig = m.getNowTable(scp)
local newConfig = {}
scp:set('config.now', newConfig)
scp:set('config.raw', {})
@@ -460,6 +472,4 @@ function m.addNullSymbol(null)
m.nullSymbols[null] = true
end
-m.update(scope.fallback, {})
-
return m
diff --git a/script/gc.lua b/script/gc.lua
index 7e4a8ab1..24a72f15 100644
--- a/script/gc.lua
+++ b/script/gc.lua
@@ -1,4 +1,4 @@
-local util = require 'share.utility'
+local util = require 'utility'
---@class gc
---@field _list table
diff --git a/script/proto/proto.lua b/script/proto/proto.lua
index 2156b7fa..2b9a6963 100644
--- a/script/proto/proto.lua
+++ b/script/proto/proto.lua
@@ -41,6 +41,12 @@ function m.on(method, callback)
m.ability[method] = callback
end
+function m.send(data)
+ local buf = jsonrpc.encode(data)
+ logSend(buf)
+ io.write(buf)
+end
+
function m.response(id, res)
if id == nil then
log.error('Response id is nil!', util.dump(res))
@@ -51,10 +57,7 @@ function m.response(id, res)
local data = {}
data.id = id
data.result = res == nil and json.null or res
- local buf = jsonrpc.encode(data)
- --log.debug('Response', id, #buf)
- logSend(buf)
- io.write(buf)
+ m.send(data)
end
function m.responseErr(id, code, message)
@@ -64,39 +67,30 @@ function m.responseErr(id, code, message)
end
assert(m.holdon[id])
m.holdon[id] = nil
- local buf = jsonrpc.encode {
+ m.send {
id = id,
error = {
code = code,
message = message,
}
}
- --log.debug('ResponseErr', id, #buf)
- logSend(buf)
- io.write(buf)
end
function m.notify(name, params)
- local buf = jsonrpc.encode {
+ m.send {
method = name,
params = params,
}
- --log.debug('Notify', name, #buf)
- logSend(buf)
- io.write(buf)
end
---@async
function m.awaitRequest(name, params)
local id = reqCounter()
- local buf = jsonrpc.encode {
+ m.send {
id = id,
method = name,
params = params,
}
- --log.debug('Request', name, #buf)
- logSend(buf)
- io.write(buf)
local result, error = await.wait(function (resume)
m.waiting[id] = resume
end)
diff --git a/script/timer.lua b/script/timer.lua
index 11a6687a..a14cdd27 100644
--- a/script/timer.lua
+++ b/script/timer.lua
@@ -12,6 +12,7 @@ local curFrame = 0
local maxFrame = 0
local curIndex = 0
local tarFrame = 0
+local fwFrame = 0
local freeQueue = {}
local timer = {}
@@ -206,7 +207,7 @@ end
local lastClock = monotonic()
function m.update()
- local currentClock = monotonic()
+ local currentClock = monotonic() + fwFrame
local delta = currentClock - lastClock
lastClock = currentClock
if curIndex ~= 0 then
@@ -220,4 +221,8 @@ function m.update()
end
end
+function m.timeJump(delta)
+ fwFrame = fwFrame + mathFloor(delta * 1000.0)
+end
+
return m
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index 5fbc18b1..c11d3e78 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -56,6 +56,7 @@ function m.reset()
m.folders = {}
m.rootUri = nil
end
+m.reset()
function m.getRootUri(uri)
local scp = m.getScope(uri)