mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-13 03:30:29 +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
|
||||
error( "bad argument #1 (expected string, got " .. type( _url ) .. ")", 2 )
|
||||
end
|
||||
if _post ~= nil and type( _post ) ~= "table" then
|
||||
error( "bad argument #2 (expected table, got " .. type( _post ) .. ")", 2 )
|
||||
if _post ~= nil and type( _post ) ~= "string" then
|
||||
error( "bad argument #2 (expected string, got " .. type( _post ) .. ")", 2 )
|
||||
end
|
||||
if _headers ~= nil and type( _headers ) ~= "table" then
|
||||
error( "bad argument #3 (expected table, got " .. type( _headers ) .. ")", 2 )
|
||||
@ -828,7 +828,7 @@ for n,sFile in ipairs( tApis ) do
|
||||
end
|
||||
end
|
||||
|
||||
if turtle then
|
||||
if turtle and fs.isDir( "rom/apis/turtle" ) then
|
||||
-- Load turtle APIs
|
||||
local tApis = fs.list( "rom/apis/turtle" )
|
||||
for n,sFile in ipairs( tApis ) do
|
||||
|
@ -233,7 +233,7 @@ function run()
|
||||
if type( tMessage ) == "table" and tMessage.nMessageID then
|
||||
if not tReceivedMessages[ tMessage.nMessageID ] then
|
||||
tReceivedMessages[ tMessage.nMessageID ] = true
|
||||
tReceivedMessageTimeouts[ os.startTimer( 30 ) ] = nMessageID
|
||||
tReceivedMessageTimeouts[ os.startTimer( 30 ) ] = tMessage.nMessageID
|
||||
os.queueEvent( "rednet_message", nReplyChannel, tMessage.message, tMessage.sProtocol )
|
||||
end
|
||||
end
|
||||
|
@ -56,6 +56,7 @@ function getNames()
|
||||
for k,v in pairs( tSettings ) do
|
||||
result[ #result + 1 ] = k
|
||||
end
|
||||
table.sort(result)
|
||||
return result
|
||||
end
|
||||
|
||||
|
@ -7,7 +7,7 @@ function slowWrite( sText, nRate )
|
||||
local nSleep = 1 / nRate
|
||||
|
||||
sText = tostring( sText )
|
||||
local x,y = term.getCursorPos(x,y)
|
||||
local x,y = term.getCursorPos()
|
||||
local len = string.len( sText )
|
||||
|
||||
for n=1,len do
|
||||
@ -338,6 +338,7 @@ end
|
||||
|
||||
local tEmpty = {}
|
||||
function complete( sSearchText, tSearchTable )
|
||||
if g_tLuaKeywords[sSearchText] then return tEmpty end
|
||||
local nStart = 1
|
||||
local nDot = string.find( sSearchText, ".", nStart, true )
|
||||
local tTable = tSearchTable or _ENV
|
||||
@ -352,8 +353,19 @@ function complete( sSearchText, tSearchTable )
|
||||
return tEmpty
|
||||
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 tResults = {}
|
||||
|
@ -175,7 +175,7 @@ local nCompletion
|
||||
local tCompleteEnv = _ENV
|
||||
local function complete( sLine )
|
||||
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
|
||||
sLine = string.sub( sLine, nStartPos )
|
||||
end
|
||||
@ -709,7 +709,13 @@ while bRunning do
|
||||
end
|
||||
|
||||
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
|
||||
local sLine = tLines[y]
|
||||
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 )
|
||||
if x == nil then
|
||||
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
|
||||
end
|
||||
end
|
||||
|
@ -34,7 +34,7 @@ while bRunning do
|
||||
|
||||
local s = read( nil, tCommandHistory, function( sLine )
|
||||
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
|
||||
sLine = string.sub( sLine, nStartPos )
|
||||
end
|
||||
@ -64,10 +64,10 @@ while bRunning do
|
||||
end
|
||||
|
||||
if func then
|
||||
local tResults = { pcall( func ) }
|
||||
local tResults = table.pack( pcall( func ) )
|
||||
if tResults[1] then
|
||||
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 ]
|
||||
if type( value ) == "table" then
|
||||
local metatable = getmetatable( value )
|
||||
|
@ -310,14 +310,14 @@ elseif sCommand == "join" then
|
||||
function printMessage( sMessage )
|
||||
term.redirect( historyWindow )
|
||||
print()
|
||||
if string.match( sMessage, "^\*" ) then
|
||||
if string.match( sMessage, "^%*" ) then
|
||||
-- Information
|
||||
term.setTextColour( highlightColour )
|
||||
write( sMessage )
|
||||
term.setTextColour( textColour )
|
||||
else
|
||||
-- Chat
|
||||
local sUsernameBit = string.match( sMessage, "^\<[^\>]*\>" )
|
||||
local sUsernameBit = string.match( sMessage, "^<[^>]*>" )
|
||||
if sUsernameBit then
|
||||
term.setTextColour( highlightColour )
|
||||
write( sUsernameBit )
|
||||
|
@ -2,9 +2,12 @@
|
||||
local tArgs = { ... }
|
||||
if #tArgs == 0 then
|
||||
-- "set"
|
||||
local x,y = term.getCursorPos()
|
||||
local tSettings = {}
|
||||
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
|
||||
textutils.pagedPrint(table.concat(tSettings,"\n"),y-3)
|
||||
|
||||
elseif #tArgs == 1 then
|
||||
-- "set foo"
|
||||
|
@ -31,6 +31,7 @@ local function createShellEnv( sDir )
|
||||
table = table,
|
||||
}
|
||||
package.path = "?;?.lua;?/init.lua"
|
||||
package.config = "/\n;\n?\n!\n-"
|
||||
package.preload = {}
|
||||
package.loaders = {
|
||||
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/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
|
||||
if fs.exists( "/rom/autorun" ) and fs.isDir( "/rom/autorun" ) then
|
||||
local tFiles = fs.list( "/rom/autorun" )
|
||||
|
Loading…
Reference in New Issue
Block a user