change editors default file to untitled.lua - add package for LuaFileSystem port
This commit is contained in:
@@ -6,6 +6,7 @@ local Util = require('opus.util')
|
||||
|
||||
local device = _G.device
|
||||
local fs = _G.fs
|
||||
local keys = _G.keys
|
||||
local multishell = _ENV.multishell
|
||||
local os = _G.os
|
||||
local shell = _ENV.shell
|
||||
@@ -905,7 +906,7 @@ actions = {
|
||||
if not force and undo.chain[#undo.chain] ~= lastSave then
|
||||
page.unsaved:show('file_new')
|
||||
else
|
||||
actions.open('/untitled.txt')
|
||||
actions.open('/untitled.lua')
|
||||
end
|
||||
end,
|
||||
|
||||
@@ -1028,6 +1029,21 @@ actions = {
|
||||
fn = fn,
|
||||
focused = true,
|
||||
title = fs.getName(fileInfo.path),
|
||||
chainExit = function(_, result)
|
||||
-- display results of process before
|
||||
-- closing window
|
||||
if result then -- clean exit
|
||||
-- any errors will be picked up by multishells
|
||||
-- error handling
|
||||
print('Press enter to exit')
|
||||
while true do
|
||||
local e, code = os.pullEventRaw('key')
|
||||
if e == 'terminate' or e == 'key' and code == keys.enter then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
else
|
||||
local ln = msg:match(':(%d+):')
|
||||
@@ -1535,7 +1551,7 @@ actions = {
|
||||
|
||||
local args = { ... }
|
||||
local filename = args[1] and shell.resolve(args[1])
|
||||
if not (actions.load(filename) or actions.load(config.filename) or actions.load('untitled.txt')) then
|
||||
if not (actions.load(filename) or actions.load(config.filename) or actions.load('untitled.lua')) then
|
||||
error('Error opening file')
|
||||
end
|
||||
|
||||
|
||||
11
lfs/.package
Normal file
11
lfs/.package
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
title = 'LuaFileSystem',
|
||||
repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/lfs',
|
||||
description = [[LuaFileSystem port for computercraft
|
||||
See: https://github.com/keplerproject/luafilesystem
|
||||
|
||||
LuaFileSystem is a Lua library developed to complement the set of functions related to file systems offered by the standard Lua distribution.
|
||||
|
||||
LuaFileSystem offers a portable way to access the underlying directory structure and file attributes. LuaFileSystem is free software and uses the same license as Lua 5.x (MIT).]],
|
||||
license = 'MIT',
|
||||
}
|
||||
1
lfs/etc/fstab
Normal file
1
lfs/etc/fstab
Normal file
@@ -0,0 +1 @@
|
||||
rom/modules/main/lfs.lua linkfs /packages/lfs/lfs.lua
|
||||
237
lfs/lfs.lua
Normal file
237
lfs/lfs.lua
Normal file
@@ -0,0 +1,237 @@
|
||||
-- a port of LuaFileSystem
|
||||
-- https://keplerproject.github.io/luafilesystem/manual.html
|
||||
|
||||
local fs = _G.fs
|
||||
local shell = _ENV.shell
|
||||
|
||||
local lfs = {
|
||||
_VERSION = '1.8.0.computercraft'
|
||||
}
|
||||
|
||||
-- lfs.attributes (filepath [, request_name | result_table])
|
||||
-- Returns a table with the file attributes corresponding to filepath (or nil followed
|
||||
-- by an error message and a system-dependent error code in case of error). If the second
|
||||
-- optional argument is given and is a string, then only the value of the named attribute
|
||||
-- is returned (this use is equivalent to lfs.attributes(filepath)[request_name], but the
|
||||
-- table is not created and only one attribute is retrieved from the O.S.). if a table is
|
||||
-- passed as the second argument, it (result_table) is filled with attributes and returned
|
||||
-- instead of a new table. The attributes are described as follows; attribute mode is a
|
||||
-- string, all the others are numbers, and the time related attributes use the same time
|
||||
-- reference of os.time:
|
||||
function lfs.attributes(path, request_name)
|
||||
path = shell.resolve(path)
|
||||
|
||||
local s, fsattr = pcall(fs.attributes, path)
|
||||
if not s then
|
||||
return nil, fsattr, 1
|
||||
end
|
||||
|
||||
local attributes = type(request_name) == 'table' and request_name or { }
|
||||
|
||||
-- on Unix systems, this represents the device that the inode resides on.
|
||||
-- On Windows systems, represents the drive number of the disk containing the file
|
||||
attributes.dev = fs.getDrive(path)
|
||||
|
||||
-- on Unix systems, this represents the inode number.
|
||||
-- On Windows systems this has no meaning
|
||||
attributes.ino = nil
|
||||
|
||||
--string representing the associated protection mode
|
||||
-- (the values could be file, directory, link, socket, named pipe,
|
||||
-- char device, block device or other)
|
||||
attributes.mode = fsattr.isDir and 'directory' or 'file'
|
||||
|
||||
-- number of hard links to the file
|
||||
attributes.nlink = 0
|
||||
|
||||
-- user-id of owner (Unix only, always 0 on Windows)
|
||||
attributes.uid = 0
|
||||
|
||||
-- group-id of owner (Unix only, always 0 on Windows)
|
||||
attributes.gid = 0
|
||||
|
||||
-- on Unix systems, represents the device type, for special file inodes.
|
||||
-- On Windows systems represents the same as dev
|
||||
attributes.rdev = attributes.dev
|
||||
|
||||
-- time of last access
|
||||
attributes.access = fsattr.modification
|
||||
|
||||
-- time of last data modification
|
||||
attributes.modification = fsattr.modification
|
||||
|
||||
-- time of last file status change
|
||||
attributes.change = fsattr.modification
|
||||
|
||||
-- file size, in bytes
|
||||
attributes.size = fsattr.size
|
||||
|
||||
-- file permissions string
|
||||
local perm = (fs.isDir or fs.isReadOnly(path)) and 'r-x' or 'rwx'
|
||||
attributes.permissions = perm .. perm .. perm
|
||||
|
||||
-- block allocated for file; (Unix only)
|
||||
attributes.blocks = nil
|
||||
|
||||
-- optimal file system I/O blocksize; (Unix only)
|
||||
attributes.blksize = nil
|
||||
|
||||
return type(request_name) ~= 'string' and attributes or attributes[request_name]
|
||||
end
|
||||
|
||||
-- lfs.chdir (path)
|
||||
-- Changes the current working directory to the given path.
|
||||
-- Returns true in case of success or nil plus an error string.
|
||||
function lfs.chdir(path)
|
||||
path = shell.resolve(path)
|
||||
if fs.isDir(path) then
|
||||
shell.setDir(path)
|
||||
return true
|
||||
end
|
||||
return nil, path .. ': No such directory'
|
||||
end
|
||||
|
||||
-- lfs.currentdir ()
|
||||
-- Returns a string with the current working directory or nil plus an error string.
|
||||
function lfs.currentdir()
|
||||
return '/' .. shell.dir()
|
||||
end
|
||||
|
||||
-- iter, dir_obj = lfs.dir (path)
|
||||
-- Lua iterator over the entries of a given directory.
|
||||
-- Each time the iterator is called with dir_obj it returns a directory
|
||||
-- entry's name as a string, or nil if there are no more entries.
|
||||
-- You can also iterate by calling dir_obj:next(), and explicitly close the
|
||||
-- directory before the iteration finished with dir_obj:close().
|
||||
-- Raises an error if path is not a directory.
|
||||
function lfs.dir(path)
|
||||
path = shell.resolve(path)
|
||||
local set = fs.list(path)
|
||||
local iter = function()
|
||||
local key, value = next(set)
|
||||
set[key or false] = nil
|
||||
return value
|
||||
end
|
||||
return iter, {
|
||||
valid = true,
|
||||
closed = false,
|
||||
next = function(self)
|
||||
if not self.valid then
|
||||
error('file iterator invalid')
|
||||
end
|
||||
local n = iter()
|
||||
if not n then
|
||||
self.valid = false
|
||||
end
|
||||
return n
|
||||
end,
|
||||
close = function(self)
|
||||
if self.closed then
|
||||
error('file iterator invalid')
|
||||
end
|
||||
self.closed = true
|
||||
self.valid = false
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
-- lfs.link (old, new[, symlink])
|
||||
-- Creates a link. The first argument is the object to link to and the second is the
|
||||
-- name of the link. If the optional third argument is true, the link will by a symbolic
|
||||
-- link (by default, a hard link is created).
|
||||
function lfs.link(old, new, symlink)
|
||||
if not symlink then
|
||||
return false
|
||||
end
|
||||
-- hard links are not supported in vfs :(
|
||||
old = shell.resolve(old)
|
||||
new = shell.resolve(new)
|
||||
return not not fs.mount(new, 'linkfs', old)
|
||||
end
|
||||
|
||||
-- lfs.mkdir (dirname)
|
||||
-- Creates a new directory. The argument is the name of the new directory.
|
||||
-- Returns true in case of success or nil, an error message and a system-dependent
|
||||
-- error code in case of error.
|
||||
function lfs.mkdir(dirname)
|
||||
dirname = shell.resolve(dirname)
|
||||
if fs.exists(fs.getDir(dirname)) then
|
||||
fs.makeDir(dirname)
|
||||
if fs.isDir(dirname) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return nil, dirname .. ': Unable to create directory', 1
|
||||
end
|
||||
|
||||
-- lfs.rmdir (dirname)
|
||||
-- Removes an existing directory. The argument is the name of the directory.
|
||||
-- Returns true in case of success or nil, an error message and a system-dependent
|
||||
-- error code in case of error.
|
||||
function lfs.rmdir(dirname)
|
||||
dirname = shell.resolve(dirname)
|
||||
if not fs.exists(dirname) or not fs.isDir(dirname) then
|
||||
return false, dirname .. ': Not a directory', 1
|
||||
end
|
||||
pcall(fs.delete, dirname)
|
||||
return not fs.exists(dirname) or false, dirname .. ': Unable to remove directory', 1
|
||||
end
|
||||
|
||||
-- lfs.setmode (file, mode)
|
||||
-- Sets the writing mode for a file. The mode string can be either "binary" or "text".
|
||||
-- Returns true followed the previous mode string for the file, or nil followed by an
|
||||
-- error string in case of errors. On non-Windows platforms, where the two modes are
|
||||
-- identical, setting the mode has no effect, and the mode is always returned as binary.
|
||||
function lfs.setmode(file)
|
||||
if tostring(file) == 'file (closed)' then
|
||||
error('closed file')
|
||||
end
|
||||
return true, 'binary'
|
||||
end
|
||||
|
||||
-- lfs.symlinkattributes (filepath [, request_name])
|
||||
-- Identical to lfs.attributes except that it obtains information about the link itself
|
||||
-- (not the file it refers to). It also adds a target field, containing the file name that
|
||||
-- the symlink points to. On Windows this function does not yet support links, and is
|
||||
-- identical to lfs.attributes.
|
||||
function lfs.symlinkattributes(filepath, request_name)
|
||||
filepath = shell.resolve(filepath)
|
||||
|
||||
local target = fs.resolve(filepath)
|
||||
local attribs = lfs.attributes('/' .. target)
|
||||
if filepath ~= target then
|
||||
attribs.target = '/' .. target
|
||||
attribs.mode = 'link'
|
||||
end
|
||||
|
||||
return request_name and attribs[request_name] or attribs
|
||||
end
|
||||
|
||||
-- lfs.touch (filepath [, atime [, mtime]])
|
||||
-- Set access and modification times of a file. This function is a bind to utime function.
|
||||
-- The first argument is the filename, the second argument (atime) is the access time, and
|
||||
-- the third argument (mtime) is the modification time. Both times are provided in seconds
|
||||
-- (which should be generated with Lua standard function os.time). If the modification time
|
||||
-- is omitted, the access time provided is used; if both times are omitted, the current time
|
||||
-- is used.
|
||||
-- Returns true in case of success or nil, an error message and a system-dependent error
|
||||
-- code in case of error.
|
||||
function lfs.touch(filename, atime, mtime)
|
||||
mtime = mtime or atime
|
||||
filename = shell.resolve(filename)
|
||||
|
||||
if atime or mtime then
|
||||
error('setting access/modification time is not supported')
|
||||
end
|
||||
|
||||
-- cc does not suport setting atime/mtime
|
||||
-- error('lfs.touch not supported')
|
||||
if not fs.exists(filename) then
|
||||
local f = fs.open(filename, 'w')
|
||||
if f then
|
||||
f.close()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return lfs
|
||||
@@ -553,7 +553,7 @@ function Storage:export(target, slot, count, item)
|
||||
|
||||
if amount ~= pcount then
|
||||
-- this *should* only happen if cache is out of sync
|
||||
-- out the target is full
|
||||
-- or... the target is full
|
||||
self:updateCache(adapter, item, pcount - amount)
|
||||
end
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
[ 'games' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/games/.package',
|
||||
-- [ 'glasses' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/glasses/.package',
|
||||
[ 'gps' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/gps/.package',
|
||||
[ 'lfs' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/lfs/.package',
|
||||
[ 'lzwfs' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/lzwfs/.package',
|
||||
[ 'mbs' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/mbs/.package',
|
||||
[ 'milo' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/milo/.package',
|
||||
|
||||
8
penlight/.package
Normal file
8
penlight/.package
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
title = 'Penlight apis',
|
||||
repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/penlight',
|
||||
description = [[See: https://github.com/Tieske/Penlight
|
||||
|
||||
Penlight brings together a set of generally useful pure Lua modules, focusing on input data handling (such as reading configuration files), functional programming (such as map, reduce, placeholder expressions, etc), and OS path management. Much of the functionality is inspired by the Python standard libraries.]],
|
||||
license = 'MIT',
|
||||
}
|
||||
1
penlight/etc/fstab
Normal file
1
penlight/etc/fstab
Normal file
@@ -0,0 +1 @@
|
||||
rom/modules/main/pl gitfs Tieske/Penlight/master/lua/pl
|
||||
19
penlight/init/6.penlight.lua
Normal file
19
penlight/init/6.penlight.lua
Normal file
@@ -0,0 +1,19 @@
|
||||
--[[
|
||||
local getfenv = _G.getfenv
|
||||
|
||||
-- penlight requires a global package to determine path separator
|
||||
-- some funky things in penlight regarding global access
|
||||
_G.package = {
|
||||
config = '/\n:\n?\n!\n-',
|
||||
}
|
||||
|
||||
_G.require = function(module)
|
||||
for i = 2, 3 do
|
||||
local env = getfenv(i)
|
||||
if env ~= _G then
|
||||
return env.require(module)
|
||||
end
|
||||
end
|
||||
error('invalid environment for require')
|
||||
end
|
||||
]]
|
||||
Reference in New Issue
Block a user