dummix: fuck this shit

Former-commit-id: 7d9983b50f218611c2d482723a88851e13fca3d0
Former-commit-id: 3891c23fd13248a869f8611dc3185d2a7a564d51
This commit is contained in:
Song Minjae
2016-10-05 22:32:37 +09:00
parent 8a71a4c852
commit 8b4baa77a4
10 changed files with 96 additions and 33 deletions

View File

@@ -22,7 +22,7 @@ class StateVTTest : BasicGameState() {
// HiRes: 100x64, LoRes: 80x25
val computerInside = BaseTerrarumComputer(8)
val vt = SimpleTextTerminal(SimpleTextTerminal.WHITE, 80, 25,
computerInside, colour = false, hires = false)
computerInside, colour = true, hires = false)
val vtUI = Image(vt.displayW, vt.displayH)

View File

@@ -100,14 +100,14 @@ constructor(gamename: String) : StateBasedGame(gamename) {
gc.graphics.clear() // clean up any 'dust' in the buffer
addState(StateVTTest())
//addState(StateVTTest())
//addState(StateTestingSandbox())
//addState(StateSplash())
//addState(StateMonitorCheck())
//addState(StateFontTester())
//ingame = StateInGame()
//addState(ingame)
ingame = StateInGame()
addState(ingame)
}
companion object {

View File

@@ -30,7 +30,7 @@ local function endsWithSlash(p)
return p:byte(#p) == 47
end
__DSHDEBUG__ = 0x51621D
--__DSHDEBUG__ = 0x51621D
local function debug(msg)
if __DSHDEBUG__ then print("DEBUG", msg) end
@@ -55,32 +55,29 @@ local function cd(tArgs)
-- parse dir by delimeter '/'
if (dir:byte(1) == 47) then -- if dir begins with '/'
os.workingDir = {""}
end
os.setWorkingDir(dir)
else
for word in string.gmatch(dir, "[^/]+") do
for word in string.gmatch(dir, "[^/]+") do
-- 'execute' directory
-- Rules: '..' pops os.workingDir
-- if dir begins with '/', re-build os.workingDir
-- otherwise, push the 'word' to os.workingDir
if (word == "..") then
if (#os.workingDir > 1) then
os.workingDir[#os.workingDir] = nil -- pops an element to oblivion
else
machine.println("CD word: "..word)
-- 'execute' directory
-- Rules: '..' pops os.workingDir
-- if dir begins with '/', re-build os.workingDir
-- otherwise, push the 'word' to os.workingDir
if (word == "..") then
os.popWorkingDir()
elseif (word == ".") then
-- pass
else
os.pushWorkingDir(word)
end
elseif (word == ".") then
-- pass
else
table.insert(os.workingDir, word)
end
end
-- check if the directory exists
if not fs.isDir(os.fullWorkPath()) then
os.errorNoSuchFileOrDir("cd: "..dir)
os.workingDir = oldWorkingDir
os.workingDir = shallowCopy(oldWorkingDir)
return
end
end

View File

@@ -31,8 +31,8 @@ local function printUsage()
end
if args[1] == nil or #args[1] <= 0 then printUsage() return end
if not fs.exists(args[1]) then os.errorNoSuchFileOrDir(args[1]) return end
if not fs.isFile(args[1]) then os.errorIsDir(args[1]) return end
filepath = os.expandPath(args[1])
if not fs.isFile(filepath) then os.errorNoSuchFile(filepath) return end
function log10(n)
if n < 1 then return 0
@@ -55,7 +55,7 @@ end
lines = {}
displayHeight = term.height() - 1 -- bottom one line for prompt
local file = fs.open(args[1], "r")
local file = fs.open(filepath, "r")
local line = ""
repeat
line = file.readLine()

View File

@@ -0,0 +1,10 @@
local args = {...}
local dir = os.fullWorkPath()--(#args < 1) and os.fullWorkPath() or args[1]
local list = fs.list("/"..dir)
table.sort(list)
for _, v in ipairs(list) do
print(v)
end

View File

View File

@@ -1,8 +1,8 @@
-- dsh aliases
os.dshenv.aliases = {
lua = "exec msh",
lua = "msh",
sh = "dsh",
shutdown = "exit",
less = "exec lessismore",
more = "exec lessismore"
shutdown = "exit", -- should be a separate program that actually halts the system
less = "lessismore",
more = "lessismore"
}

View File

@@ -23,10 +23,61 @@ end
if not _G.os then _G.os = {} end
os.version = "0.0"
os.EXIT_SUCCESS = 0
os.workingDir = {"", "home"} -- index 1 must be ""!
os.workingDir = {"home"}
os.path = "home/bin/;/usr/bin/;/bin/" -- infamous $path
os.fullWorkPath = function()
return table.concat(os.workingDir, "/")
local ret = table.concat(os.workingDir, "/") -- there's nothing wrong with this.
if computer.verbose then
machine.println("workingDir size: "..#os.workingDir)
machine.println("fullWorkPath: "..ret)
end
return ret
end
os.setWorkingDir = function(s)
if s:byte(#s) == 47 then
s = string.sub(s, 1, #s - 1)
end
if s:byte(1) == 47 then
s = string.sub(s, 2, #s)
end
if computer.verbose then
machine.println("renew working dir; '"..s.."'")
end
local oldWorkingDir = {table.unpack(os.workingDir)}
-- renew working directory, EVEN IF s STARTS WITH '/'
local t = {}
for word in string.gmatch(s, "[^/]+") do
table.insert(t, word)
end
os.workingDir = t
-- check if the directory exists
if not fs.isDir(s) then
os.errorNoSuchFileOrDir("cd: "..s)
os.workingDir = oldWorkingDir
return
end
end
os.pushWorkingDir = function(s)
if (s == "..") then
error("cannot push '..' to working directory.")
else
table.insert(os.workingDir, s)
if computer.verbose then
machine.println("pushing '"..s.."' to working directory.")
end
end
end
os.popWorkingDir = function()
if (#os.workingDir > 1) then
table.remove(os.workingDir)
end
end
-- @param "path/of/arbitrary"
-- @return /working/dir/path/of/arbitrary

View File

@@ -139,6 +139,8 @@ internal class Filesystem(globals: Globals, computer: BaseTerrarumComputer) {
override fun call(path: LuaValue) : LuaValue {
Filesystem.ensurePathSanity(path)
println("ListFiles: got path ${path.checkIBM437()}")
val table = LuaTable()
val file = File(computer.getRealPath(path)).absoluteFile
try {
@@ -162,7 +164,10 @@ internal class Filesystem(globals: Globals, computer: BaseTerrarumComputer) {
override fun call(path: LuaValue) : LuaValue {
Filesystem.ensurePathSanity(path)
return LuaValue.valueOf(Files.isDirectory(Paths.get(computer.getRealPath(path)).toAbsolutePath()))
val isDir = Files.isDirectory(Paths.get(computer.getRealPath(path)).toAbsolutePath())
val exists = Files.exists(Paths.get(computer.getRealPath(path)).toAbsolutePath())
return LuaValue.valueOf(isDir || exists)
}
}