mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-13 19:50:31 +00:00
Merge pull request #317 from Wojbie/Mixed-lua-side-improvements
Multiple fixes and feature fixes for lua side of CC.
This commit is contained in:
commit
14e4d037ad
@ -729,8 +729,8 @@ if http then
|
|||||||
if type( _url ) ~= "string" then
|
if type( _url ) ~= "string" then
|
||||||
error( "bad argument #1 (expected string, got " .. type( _url ) .. ")", 2 )
|
error( "bad argument #1 (expected string, got " .. type( _url ) .. ")", 2 )
|
||||||
end
|
end
|
||||||
if _post ~= nil and type( _post ) ~= "table" then
|
if _post ~= nil and type( _post ) ~= "string" then
|
||||||
error( "bad argument #2 (expected table, got " .. type( _post ) .. ")", 2 )
|
error( "bad argument #2 (expected string, got " .. type( _post ) .. ")", 2 )
|
||||||
end
|
end
|
||||||
if _headers ~= nil and type( _headers ) ~= "table" then
|
if _headers ~= nil and type( _headers ) ~= "table" then
|
||||||
error( "bad argument #3 (expected table, got " .. type( _headers ) .. ")", 2 )
|
error( "bad argument #3 (expected table, got " .. type( _headers ) .. ")", 2 )
|
||||||
@ -828,7 +828,7 @@ for n,sFile in ipairs( tApis ) do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if turtle then
|
if turtle and fs.isDir( "rom/apis/turtle" ) then
|
||||||
-- Load turtle APIs
|
-- Load turtle APIs
|
||||||
local tApis = fs.list( "rom/apis/turtle" )
|
local tApis = fs.list( "rom/apis/turtle" )
|
||||||
for n,sFile in ipairs( tApis ) do
|
for n,sFile in ipairs( tApis ) do
|
||||||
|
@ -233,7 +233,7 @@ function run()
|
|||||||
if type( tMessage ) == "table" and tMessage.nMessageID then
|
if type( tMessage ) == "table" and tMessage.nMessageID then
|
||||||
if not tReceivedMessages[ tMessage.nMessageID ] then
|
if not tReceivedMessages[ tMessage.nMessageID ] then
|
||||||
tReceivedMessages[ tMessage.nMessageID ] = true
|
tReceivedMessages[ tMessage.nMessageID ] = true
|
||||||
tReceivedMessageTimeouts[ os.startTimer( 30 ) ] = nMessageID
|
tReceivedMessageTimeouts[ os.startTimer( 30 ) ] = tMessage.nMessageID
|
||||||
os.queueEvent( "rednet_message", nReplyChannel, tMessage.message, tMessage.sProtocol )
|
os.queueEvent( "rednet_message", nReplyChannel, tMessage.message, tMessage.sProtocol )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -56,6 +56,7 @@ function getNames()
|
|||||||
for k,v in pairs( tSettings ) do
|
for k,v in pairs( tSettings ) do
|
||||||
result[ #result + 1 ] = k
|
result[ #result + 1 ] = k
|
||||||
end
|
end
|
||||||
|
table.sort(result)
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ function slowWrite( sText, nRate )
|
|||||||
local nSleep = 1 / nRate
|
local nSleep = 1 / nRate
|
||||||
|
|
||||||
sText = tostring( sText )
|
sText = tostring( sText )
|
||||||
local x,y = term.getCursorPos(x,y)
|
local x,y = term.getCursorPos()
|
||||||
local len = string.len( sText )
|
local len = string.len( sText )
|
||||||
|
|
||||||
for n=1,len do
|
for n=1,len do
|
||||||
@ -338,6 +338,7 @@ end
|
|||||||
|
|
||||||
local tEmpty = {}
|
local tEmpty = {}
|
||||||
function complete( sSearchText, tSearchTable )
|
function complete( sSearchText, tSearchTable )
|
||||||
|
if g_tLuaKeywords[sSearchText] then return tEmpty end
|
||||||
local nStart = 1
|
local nStart = 1
|
||||||
local nDot = string.find( sSearchText, ".", nStart, true )
|
local nDot = string.find( sSearchText, ".", nStart, true )
|
||||||
local tTable = tSearchTable or _ENV
|
local tTable = tSearchTable or _ENV
|
||||||
@ -352,8 +353,19 @@ function complete( sSearchText, tSearchTable )
|
|||||||
return tEmpty
|
return tEmpty
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
local nColon = string.find( sSearchText, ":", nStart, true )
|
||||||
|
if nColon then
|
||||||
|
local sPart = string.sub( sSearchText, nStart, nColon - 1 )
|
||||||
|
local value = tTable[ sPart ]
|
||||||
|
if type( value ) == "table" then
|
||||||
|
tTable = value
|
||||||
|
nStart = nColon + 1
|
||||||
|
else
|
||||||
|
return tEmpty
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local sPart = string.sub( sSearchText, nStart, nDot )
|
local sPart = string.sub( sSearchText, nStart )
|
||||||
local nPartLength = string.len( sPart )
|
local nPartLength = string.len( sPart )
|
||||||
|
|
||||||
local tResults = {}
|
local tResults = {}
|
||||||
|
@ -175,7 +175,7 @@ local nCompletion
|
|||||||
local tCompleteEnv = _ENV
|
local tCompleteEnv = _ENV
|
||||||
local function complete( sLine )
|
local function complete( sLine )
|
||||||
if settings.get( "edit.autocomplete" ) then
|
if settings.get( "edit.autocomplete" ) then
|
||||||
local nStartPos = string.find( sLine, "[a-zA-Z0-9_%.]+$" )
|
local nStartPos = string.find( sLine, "[a-zA-Z0-9_%.:]+$" )
|
||||||
if nStartPos then
|
if nStartPos then
|
||||||
sLine = string.sub( sLine, nStartPos )
|
sLine = string.sub( sLine, nStartPos )
|
||||||
end
|
end
|
||||||
@ -709,7 +709,13 @@ while bRunning do
|
|||||||
end
|
end
|
||||||
|
|
||||||
elseif sEvent == "paste" then
|
elseif sEvent == "paste" then
|
||||||
if not bMenu and not bReadOnly then
|
if not bReadOnly then
|
||||||
|
-- Close menu if open
|
||||||
|
if bMenu then
|
||||||
|
bMenu = false
|
||||||
|
term.setCursorBlink( true )
|
||||||
|
redrawMenu()
|
||||||
|
end
|
||||||
-- Input text
|
-- Input text
|
||||||
local sLine = tLines[y]
|
local sLine = tLines[y]
|
||||||
tLines[y] = string.sub(sLine,1,x-1) .. param .. string.sub(sLine,x)
|
tLines[y] = string.sub(sLine,1,x-1) .. param .. string.sub(sLine,x)
|
||||||
|
@ -57,10 +57,6 @@ elseif sCommand == "host" then
|
|||||||
x,y,z = gps.locate( 2, true )
|
x,y,z = gps.locate( 2, true )
|
||||||
if x == nil then
|
if x == nil then
|
||||||
print( "Run \"gps host <x> <y> <z>\" to set position manually" )
|
print( "Run \"gps host <x> <y> <z>\" to set position manually" )
|
||||||
if bCloseChannel then
|
|
||||||
print( "Closing GPS channel" )
|
|
||||||
modem.close( gps.CHANNEL_GPS )
|
|
||||||
end
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -34,7 +34,7 @@ while bRunning do
|
|||||||
|
|
||||||
local s = read( nil, tCommandHistory, function( sLine )
|
local s = read( nil, tCommandHistory, function( sLine )
|
||||||
if settings.get( "lua.autocomplete" ) then
|
if settings.get( "lua.autocomplete" ) then
|
||||||
local nStartPos = string.find( sLine, "[a-zA-Z0-9_%.]+$" )
|
local nStartPos = string.find( sLine, "[a-zA-Z0-9_%.:]+$" )
|
||||||
if nStartPos then
|
if nStartPos then
|
||||||
sLine = string.sub( sLine, nStartPos )
|
sLine = string.sub( sLine, nStartPos )
|
||||||
end
|
end
|
||||||
@ -64,10 +64,10 @@ while bRunning do
|
|||||||
end
|
end
|
||||||
|
|
||||||
if func then
|
if func then
|
||||||
local tResults = { pcall( func ) }
|
local tResults = table.pack( pcall( func ) )
|
||||||
if tResults[1] then
|
if tResults[1] then
|
||||||
local n = 1
|
local n = 1
|
||||||
while (tResults[n + 1] ~= nil) or (n <= nForcePrint) do
|
while n < tResults.n or (n <= nForcePrint) do
|
||||||
local value = tResults[ n + 1 ]
|
local value = tResults[ n + 1 ]
|
||||||
if type( value ) == "table" then
|
if type( value ) == "table" then
|
||||||
local metatable = getmetatable( value )
|
local metatable = getmetatable( value )
|
||||||
|
@ -310,14 +310,14 @@ elseif sCommand == "join" then
|
|||||||
function printMessage( sMessage )
|
function printMessage( sMessage )
|
||||||
term.redirect( historyWindow )
|
term.redirect( historyWindow )
|
||||||
print()
|
print()
|
||||||
if string.match( sMessage, "^\*" ) then
|
if string.match( sMessage, "^%*" ) then
|
||||||
-- Information
|
-- Information
|
||||||
term.setTextColour( highlightColour )
|
term.setTextColour( highlightColour )
|
||||||
write( sMessage )
|
write( sMessage )
|
||||||
term.setTextColour( textColour )
|
term.setTextColour( textColour )
|
||||||
else
|
else
|
||||||
-- Chat
|
-- Chat
|
||||||
local sUsernameBit = string.match( sMessage, "^\<[^\>]*\>" )
|
local sUsernameBit = string.match( sMessage, "^<[^>]*>" )
|
||||||
if sUsernameBit then
|
if sUsernameBit then
|
||||||
term.setTextColour( highlightColour )
|
term.setTextColour( highlightColour )
|
||||||
write( sUsernameBit )
|
write( sUsernameBit )
|
||||||
|
@ -2,9 +2,12 @@
|
|||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
if #tArgs == 0 then
|
if #tArgs == 0 then
|
||||||
-- "set"
|
-- "set"
|
||||||
|
local x,y = term.getCursorPos()
|
||||||
|
local tSettings = {}
|
||||||
for n,sName in ipairs( settings.getNames() ) do
|
for n,sName in ipairs( settings.getNames() ) do
|
||||||
print( textutils.serialize(sName) .. " is " .. textutils.serialize(settings.get(sName)) )
|
tSettings[n] = textutils.serialize(sName) .. " is " .. textutils.serialize(settings.get(sName))
|
||||||
end
|
end
|
||||||
|
textutils.pagedPrint(table.concat(tSettings,"\n"),y-3)
|
||||||
|
|
||||||
elseif #tArgs == 1 then
|
elseif #tArgs == 1 then
|
||||||
-- "set foo"
|
-- "set foo"
|
||||||
|
@ -31,6 +31,7 @@ local function createShellEnv( sDir )
|
|||||||
table = table,
|
table = table,
|
||||||
}
|
}
|
||||||
package.path = "?;?.lua;?/init.lua"
|
package.path = "?;?.lua;?/init.lua"
|
||||||
|
package.config = "/\n;\n?\n!\n-"
|
||||||
package.preload = {}
|
package.preload = {}
|
||||||
package.loaders = {
|
package.loaders = {
|
||||||
function( name )
|
function( name )
|
||||||
|
@ -205,6 +205,35 @@ shell.setCompletionFunction( "rom/programs/http/pastebin.lua", completePastebin
|
|||||||
shell.setCompletionFunction( "rom/programs/rednet/chat.lua", completeChat )
|
shell.setCompletionFunction( "rom/programs/rednet/chat.lua", completeChat )
|
||||||
shell.setCompletionFunction( "rom/programs/command/exec.lua", completeExec )
|
shell.setCompletionFunction( "rom/programs/command/exec.lua", completeExec )
|
||||||
|
|
||||||
|
if turtle then
|
||||||
|
local tGoOptions = { "left", "right", "forward", "back", "down", "up" }
|
||||||
|
local function completeGo( shell, nIndex, sText )
|
||||||
|
return completeMultipleChoice(sText,tGoOptions)
|
||||||
|
end
|
||||||
|
local tTurnOptions = { "left", "right" }
|
||||||
|
local function completeTurn( shell, nIndex, sText )
|
||||||
|
if nIndex == 1 then
|
||||||
|
return completeMultipleChoice( sText, tTurnOptions )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local tEquipOptions = { "left", "right" }
|
||||||
|
local function completeEquip( shell, nIndex, sText )
|
||||||
|
if nIndex == 2 then
|
||||||
|
return completeMultipleChoice( sText, tEquipOptions )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local function completeUnequip( shell, nIndex, sText )
|
||||||
|
if nIndex == 1 then
|
||||||
|
return completeMultipleChoice( sText, tEquipOptions )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
shell.setCompletionFunction( "rom/programs/turtle/go.lua", completeGo )
|
||||||
|
shell.setCompletionFunction( "rom/programs/turtle/turn.lua", completeTurn )
|
||||||
|
shell.setCompletionFunction( "rom/programs/turtle/equip.lua", completeEquip )
|
||||||
|
shell.setCompletionFunction( "rom/programs/turtle/unequip.lua", completeUnequip )
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Run autorun files
|
-- Run autorun files
|
||||||
if fs.exists( "/rom/autorun" ) and fs.isDir( "/rom/autorun" ) then
|
if fs.exists( "/rom/autorun" ) and fs.isDir( "/rom/autorun" ) then
|
||||||
local tFiles = fs.list( "/rom/autorun" )
|
local tFiles = fs.list( "/rom/autorun" )
|
||||||
|
Loading…
Reference in New Issue
Block a user