mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-06-16 13:34:12 +00:00
Some cleanup to the Lua programs
This commit is contained in:
parent
d847a4d9e0
commit
e5cc345f49
@ -2,11 +2,10 @@
|
|||||||
|
|
||||||
(sources
|
(sources
|
||||||
/doc/stub/
|
/doc/stub/
|
||||||
/src/main/resources/assets/computercraft/lua/bios.lua
|
/src/main/resources/data/computercraft/lua/bios.lua
|
||||||
/src/main/resources/assets/computercraft/lua/rom/
|
/src/main/resources/data/computercraft/lua/rom/
|
||||||
/src/test/resources/test-rom)
|
/src/test/resources/test-rom)
|
||||||
|
|
||||||
|
|
||||||
(doc
|
(doc
|
||||||
(title "CC: Tweaked")
|
(title "CC: Tweaked")
|
||||||
(index doc/index.md)
|
(index doc/index.md)
|
||||||
@ -15,13 +14,13 @@
|
|||||||
(library-path
|
(library-path
|
||||||
/doc/stub/
|
/doc/stub/
|
||||||
|
|
||||||
/src/main/resources/assets/computercraft/lua/rom/apis
|
/src/main/resources/data/computercraft/lua/rom/apis
|
||||||
/src/main/resources/assets/computercraft/lua/rom/apis/command
|
/src/main/resources/data/computercraft/lua/rom/apis/command
|
||||||
/src/main/resources/assets/computercraft/lua/rom/apis/turtle
|
/src/main/resources/data/computercraft/lua/rom/apis/turtle
|
||||||
|
|
||||||
/src/main/resources/assets/computercraft/lua/rom/modules/main
|
/src/main/resources/data/computercraft/lua/rom/modules/main
|
||||||
/src/main/resources/assets/computercraft/lua/rom/modules/command
|
/src/main/resources/data/computercraft/lua/rom/modules/command
|
||||||
/src/main/resources/assets/computercraft/lua/rom/modules/turtle))
|
/src/main/resources/data/computercraft/lua/rom/modules/turtle))
|
||||||
|
|
||||||
(at /
|
(at /
|
||||||
(linters
|
(linters
|
||||||
@ -50,8 +49,8 @@
|
|||||||
;; We disable the unused global linter in bios.lua and the APIs. In the future
|
;; We disable the unused global linter in bios.lua and the APIs. In the future
|
||||||
;; hopefully we'll get illuaminate to handle this.
|
;; hopefully we'll get illuaminate to handle this.
|
||||||
(at
|
(at
|
||||||
(/src/main/resources/assets/computercraft/lua/bios.lua
|
(/src/main/resources/data/computercraft/lua/bios.lua
|
||||||
/src/main/resources/assets/computercraft/lua/rom/apis/)
|
/src/main/resources/data/computercraft/lua/rom/apis/)
|
||||||
(linters -var:unused-global)
|
(linters -var:unused-global)
|
||||||
(lint (allow-toplevel-global true)))
|
(lint (allow-toplevel-global true)))
|
||||||
|
|
||||||
@ -62,17 +61,17 @@
|
|||||||
|
|
||||||
;; Ensure any fully documented modules stay fully documented.
|
;; Ensure any fully documented modules stay fully documented.
|
||||||
(at
|
(at
|
||||||
(/src/main/resources/assets/computercraft/lua/rom/apis/colors.lua
|
(/src/main/resources/data/computercraft/lua/rom/apis/colors.lua
|
||||||
/src/main/resources/assets/computercraft/lua/rom/apis/colours.lua
|
/src/main/resources/data/computercraft/lua/rom/apis/colours.lua
|
||||||
/src/main/resources/assets/computercraft/lua/rom/apis/disk.lua
|
/src/main/resources/data/computercraft/lua/rom/apis/disk.lua
|
||||||
/src/main/resources/assets/computercraft/lua/rom/apis/gps.lua
|
/src/main/resources/data/computercraft/lua/rom/apis/gps.lua
|
||||||
/src/main/resources/assets/computercraft/lua/rom/apis/help.lua
|
/src/main/resources/data/computercraft/lua/rom/apis/help.lua
|
||||||
/src/main/resources/assets/computercraft/lua/rom/apis/keys.lua
|
/src/main/resources/data/computercraft/lua/rom/apis/keys.lua
|
||||||
/src/main/resources/assets/computercraft/lua/rom/apis/paintutils.lua
|
/src/main/resources/data/computercraft/lua/rom/apis/paintutils.lua
|
||||||
/src/main/resources/assets/computercraft/lua/rom/apis/parallel.lua
|
/src/main/resources/data/computercraft/lua/rom/apis/parallel.lua
|
||||||
/src/main/resources/assets/computercraft/lua/rom/apis/peripheral.lua
|
/src/main/resources/data/computercraft/lua/rom/apis/peripheral.lua
|
||||||
/src/main/resources/assets/computercraft/lua/rom/apis/rednet.lua
|
/src/main/resources/data/computercraft/lua/rom/apis/rednet.lua
|
||||||
/src/main/resources/assets/computercraft/lua/rom/apis/settings.lua
|
/src/main/resources/data/computercraft/lua/rom/apis/settings.lua
|
||||||
/src/main/resources/assets/computercraft/lua/rom/apis/texutils.lua
|
/src/main/resources/data/computercraft/lua/rom/apis/texutils.lua
|
||||||
/src/main/resources/assets/computercraft/lua/rom/apis/vector.lua)
|
/src/main/resources/data/computercraft/lua/rom/apis/vector.lua)
|
||||||
(linters doc:undocumented doc:undocumented-arg))
|
(linters doc:undocumented doc:undocumented-arg))
|
||||||
|
@ -7,7 +7,6 @@ package dan200.computercraft;
|
|||||||
|
|
||||||
import dan200.computercraft.api.turtle.event.TurtleAction;
|
import dan200.computercraft.api.turtle.event.TurtleAction;
|
||||||
import dan200.computercraft.core.apis.AddressPredicate;
|
import dan200.computercraft.core.apis.AddressPredicate;
|
||||||
import dan200.computercraft.core.apis.http.websocket.Websocket;
|
|
||||||
import dan200.computercraft.shared.Config;
|
import dan200.computercraft.shared.Config;
|
||||||
import dan200.computercraft.shared.computer.blocks.BlockComputer;
|
import dan200.computercraft.shared.computer.blocks.BlockComputer;
|
||||||
import dan200.computercraft.shared.computer.core.ClientComputerRegistry;
|
import dan200.computercraft.shared.computer.core.ClientComputerRegistry;
|
||||||
@ -22,9 +21,9 @@ import dan200.computercraft.shared.peripheral.modem.wired.BlockWiredModemFull;
|
|||||||
import dan200.computercraft.shared.peripheral.modem.wired.ItemBlockCable;
|
import dan200.computercraft.shared.peripheral.modem.wired.ItemBlockCable;
|
||||||
import dan200.computercraft.shared.peripheral.modem.wireless.BlockWirelessModem;
|
import dan200.computercraft.shared.peripheral.modem.wireless.BlockWirelessModem;
|
||||||
import dan200.computercraft.shared.peripheral.monitor.BlockMonitor;
|
import dan200.computercraft.shared.peripheral.monitor.BlockMonitor;
|
||||||
|
import dan200.computercraft.shared.peripheral.monitor.MonitorRenderer;
|
||||||
import dan200.computercraft.shared.peripheral.printer.BlockPrinter;
|
import dan200.computercraft.shared.peripheral.printer.BlockPrinter;
|
||||||
import dan200.computercraft.shared.peripheral.speaker.BlockSpeaker;
|
import dan200.computercraft.shared.peripheral.speaker.BlockSpeaker;
|
||||||
import dan200.computercraft.shared.peripheral.monitor.MonitorRenderer;
|
|
||||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||||
import dan200.computercraft.shared.pocket.peripherals.PocketModem;
|
import dan200.computercraft.shared.pocket.peripherals.PocketModem;
|
||||||
import dan200.computercraft.shared.pocket.peripherals.PocketSpeaker;
|
import dan200.computercraft.shared.pocket.peripherals.PocketSpeaker;
|
||||||
|
@ -95,10 +95,10 @@ public class OSAPI implements ILuaAPI
|
|||||||
if( time > previousTime || day > previousDay )
|
if( time > previousTime || day > previousDay )
|
||||||
{
|
{
|
||||||
double now = m_day * 24.0 + m_time;
|
double now = m_day * 24.0 + m_time;
|
||||||
Iterator<Map.Entry<Integer, Alarm>> it = m_alarms.entrySet().iterator();
|
Iterator<Int2ObjectMap.Entry<Alarm>> it = m_alarms.int2ObjectEntrySet().iterator();
|
||||||
while( it.hasNext() )
|
while( it.hasNext() )
|
||||||
{
|
{
|
||||||
Map.Entry<Integer, Alarm> entry = it.next();
|
Int2ObjectMap.Entry<Alarm> entry = it.next();
|
||||||
Alarm alarm = entry.getValue();
|
Alarm alarm = entry.getValue();
|
||||||
double t = alarm.m_day * 24.0 + alarm.m_time;
|
double t = alarm.m_day * 24.0 + alarm.m_time;
|
||||||
if( now >= t )
|
if( now >= t )
|
||||||
|
@ -50,7 +50,7 @@ end
|
|||||||
local tAsync = {}
|
local tAsync = {}
|
||||||
local tNonNBTJSONCommands = {
|
local tNonNBTJSONCommands = {
|
||||||
["tellraw"] = true,
|
["tellraw"] = true,
|
||||||
[ "title" ] = true
|
["title"] = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
local command_mt = {}
|
local command_mt = {}
|
||||||
@ -65,6 +65,16 @@ function command_mt.__tostring(self)
|
|||||||
return ("command %q"):format("/" .. table.concat(meta.name, " "))
|
return ("command %q"):format("/" .. table.concat(meta.name, " "))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function mk_command(name, json, func)
|
||||||
|
return setmetatable({
|
||||||
|
[command_mt] = {
|
||||||
|
name = name,
|
||||||
|
func = func,
|
||||||
|
json = json,
|
||||||
|
},
|
||||||
|
}, command_mt)
|
||||||
|
end
|
||||||
|
|
||||||
function command_mt.__index(self, key)
|
function command_mt.__index(self, key)
|
||||||
local meta = self[command_mt]
|
local meta = self[command_mt]
|
||||||
if meta.children then return nil end
|
if meta.children then return nil end
|
||||||
@ -74,12 +84,7 @@ function command_mt.__index(self, key)
|
|||||||
for _, child in ipairs(native.list(table.unpack(name))) do
|
for _, child in ipairs(native.list(table.unpack(name))) do
|
||||||
local child_name = { table.unpack(name) }
|
local child_name = { table.unpack(name) }
|
||||||
child_name[#child_name + 1] = child
|
child_name[#child_name + 1] = child
|
||||||
|
self[child] = mk_command(child_name, meta.json, meta.func)
|
||||||
self[child] = setmetatable({ [command_mt] = {
|
|
||||||
name = child_name,
|
|
||||||
func = meta.func,
|
|
||||||
json = meta.json
|
|
||||||
} }, command_mt)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return self[key]
|
return self[key]
|
||||||
@ -88,17 +93,8 @@ end
|
|||||||
for _, sCommandName in ipairs(native.list()) do
|
for _, sCommandName in ipairs(native.list()) do
|
||||||
if env[sCommandName] == nil then
|
if env[sCommandName] == nil then
|
||||||
local bJSONIsNBT = tNonNBTJSONCommands[sCommandName] == nil
|
local bJSONIsNBT = tNonNBTJSONCommands[sCommandName] == nil
|
||||||
env[ sCommandName ] = setmetatable({ [command_mt] = {
|
env[sCommandName] = mk_command({ sCommandName }, bJSONIsNBT, native.exec)
|
||||||
name = { sCommandName },
|
tAsync[sCommandName] = mk_command({ sCommandName }, bJSONIsNBT, native.execAsync)
|
||||||
func = native.exec,
|
|
||||||
json = bJSONIsNBT
|
|
||||||
} }, command_mt)
|
|
||||||
|
|
||||||
tAsync[ sCommandName ] = setmetatable({ [command_mt] = {
|
|
||||||
name = { sCommandName },
|
|
||||||
func = native.execAsync,
|
|
||||||
json = bJSONIsNBT
|
|
||||||
} }, command_mt)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
env.async = tAsync
|
env.async = tAsync
|
||||||
|
Loading…
x
Reference in New Issue
Block a user