Add direct=true information to components

Add direct = true, wherever necessary
Add documentation to ocemu component

Fix up old list.lua program to output using new mai syste
Rename list.lua to gencomp.lua
This commit is contained in:
gamax92 2016-12-03 12:57:28 -07:00
parent 1a577499e5
commit d8a4718681
8 changed files with 67 additions and 58 deletions

View File

@ -1,10 +1,12 @@
local args = { ... }
if #args ~= 1 then
print("Usage: gencomp address")
return
end
local component = require("component")
local address = component.get(args[1])
local proxy = component.proxy(address)
local direct = component.methods(address)
print(proxy.type)
local keys = {}
for k,v in pairs(proxy) do
@ -14,25 +16,18 @@ for k,v in pairs(proxy) do
end
table.sort(keys,function(a,b) return a:reverse() < b:reverse() end)
local file = io.open("list.txt","wb")
file = file:write("-- " .. proxy.type .. " component\nlocal obj = {}\n\n")
file = file:write("-- " .. proxy.type .. " component\nlocal mai = {}\nlocal obj = {}\n")
for i = 1,#keys do
local k = keys[i]
local doc = ""
local comment = "-- no doc"
local comment
if component.doc(address,k) ~= nil then
doc = component.doc(address,k):match("%((.-)%)"):gsub("[%[%]]","") .. ","
doc = doc:gsub("(.-):.-,",function(a) return a .. "," end):sub(1,-2)
comment = component.doc(address,k):match("%-%-.*")
comment = component.doc(address,k)
end
file:write("function obj." .. k .. "(" .. doc .. ") " .. comment .."\n\t--STUB\n\tcprint(\"" .. proxy.type .. "." .. k .. "\"" .. (doc ~= "" and "," or "") .. doc .. ")\nend\n")
file:write("\nmai." .. k .. " = {" .. (direct[k] and "direct = true, " or "") .. string.format("doc = %q}\n", comment))
file:write("function obj." .. k .. "(" .. doc .. ")\n\t--STUB\n\tcprint(\"" .. proxy.type .. "." .. k .. "\"" .. (doc ~= "" and ", " or "") .. doc .. ")\nend\n")
end
file:write("\nlocal cec = {}\n\nlocal doc = {\n")
for i = 1,#keys do
local k = keys[i]
if component.doc(address,k) ~= nil then
local doc = component.doc(address,k)
file:write(string.format("\t[%q]=%q,\n",k,doc))
end
end
file:write("}\n\nreturn obj,cec,doc")
file:write("\nreturn obj,nil,mai")
file:close()

View File

@ -2,7 +2,7 @@
local mai = {}
local obj = {}
mai.isRunning = {doc = "function():boolean -- Returns whether the computer is running."}
mai.isRunning = {direct = true, doc = "function():boolean -- Returns whether the computer is running."}
function obj.isRunning()
--STUB
cprint("computer.isRunning")
@ -38,6 +38,12 @@ function obj.start()
cprint("computer.start")
end
mai.getDeviceInfo = {direct = true, doc = "function():table -- Collect information on all connected devices."}
function obj.getDeviceInfo()
--STUB
cprint("computer.getDeviceInfo")
end
mai.getProgramLocations = {doc = "function():table -- Returns a list of available programs and their install disks."}
function obj.getProgramLocations()
cprint("computer.getProgramLocations")

View File

@ -48,7 +48,7 @@ end
local mai = {}
local obj = {}
mai.getData = {doc = "function():string -- Get the currently stored byte array."}
mai.getData = {direct = true, doc = "function():string -- Get the currently stored byte array."}
function obj.getData()
cprint("eeprom.getData")
return data
@ -66,19 +66,19 @@ function obj.setData(newdata)
persist()
end
mai.getDataSize = {doc = "function():string -- Get the storage capacity of this EEPROM."}
mai.getDataSize = {direct = true, doc = "function():string -- Get the storage capacity of this EEPROM."}
function obj.getDataSize()
cprint("eeprom.getDataSize")
return 256
end
mai.getSize = {doc = "function():string -- Get the storage capacity of this EEPROM."}
mai.getSize = {direct = true, doc = "function():string -- Get the storage capacity of this EEPROM."}
function obj.getSize()
cprint("eeprom.getSize")
return 4096
end
mai.getLabel = {doc = "function():string -- Get the label of the EEPROM."}
mai.getLabel = {direct = true, doc = "function():string -- Get the label of the EEPROM."}
function obj.getLabel()
cprint("eeprom.getLabel")
return label
@ -97,13 +97,13 @@ function obj.setLabel(newlabel)
return label
end
mai.getChecksum = {doc = "function():string -- Get the checksum of the data on this EEPROM."}
mai.getChecksum = {direct = true, doc = "function():string -- Get the checksum of the data on this EEPROM."}
function obj.getChecksum()
cprint("eeprom.getChecksum")
return string.format("%08x", tonumber(crc32(code)))
end
mai.get = {doc = "function():string -- Get the currently stored byte array."}
mai.get = {direct = true, doc = "function():string -- Get the currently stored byte array."}
function obj.get() -- Get the currently stored byte array.
cprint("eeprom.get")
return code
@ -124,7 +124,7 @@ function obj.set(newcode) -- Overwrite the currently stored byte array.
persist()
end
mai.makeReadonly = {doc = "function(checksum:string):boolean -- Make this EEPROM readonly if it isn't already. This process cannot be reversed!"}
mai.makeReadonly = {direct = true, doc = "function(checksum:string):boolean -- Make this EEPROM readonly if it isn't already. This process cannot be reversed!"}
function obj.makeReadonly(checksum) -- Make this EEPROM readonly if it isn't already. This process cannot be reversed!
cprint("eeprom.makeReadonly", checksum)
compCheckArg(1,checksum,"string")

View File

@ -44,7 +44,7 @@ end
local mai = {}
local obj = {}
mai.read = {doc = "function(handle:number, count:number):string or nil -- Reads up to the specified amount of data from an open file descriptor with the specified handle. Returns nil when EOF is reached."}
mai.read = {direct = true, doc = "function(handle:number, count:number):string or nil -- Reads up to the specified amount of data from an open file descriptor with the specified handle. Returns nil when EOF is reached."}
function obj.read(handle, count)
--TODO
cprint("filesystem.read", handle, count)
@ -60,7 +60,7 @@ function obj.read(handle, count)
return table.unpack(ret)
end
mai.lastModified = {doc = "function(path:string):number -- Returns the (real world) timestamp of when the object at the specified absolute path in the file system was modified."}
mai.lastModified = {direct = true, doc = "function(path:string):number -- Returns the (real world) timestamp of when the object at the specified absolute path in the file system was modified."}
function obj.lastModified(path)
cprint("filesystem.lastModified", path)
compCheckArg(1,path,"string")
@ -71,7 +71,7 @@ function obj.lastModified(path)
return elsa.filesystem.getLastModified(directory .. "/" .. path) or 0
end
mai.spaceUsed = {doc = "function():number -- The currently used capacity of the file system, in bytes."}
mai.spaceUsed = {direct = true, doc = "function():number -- The currently used capacity of the file system, in bytes."}
function obj.spaceUsed()
--STUB
cprint("filesystem.spaceUsed")
@ -105,7 +105,7 @@ function obj.rename(from, to)
end
end
mai.close = {doc = "function(handle:number) -- Closes an open file descriptor with the specified handle."}
mai.close = {direct = true, doc = "function(handle:number) -- Closes an open file descriptor with the specified handle."}
function obj.close(handle)
cprint("filesystem.close", handle)
compCheckArg(1,handle,"number")
@ -116,7 +116,7 @@ function obj.close(handle)
handles[handle] = nil
end
mai.write = {doc = "function(handle:number, value:string):boolean -- Writes the specified data to an open file descriptor with the specified handle."}
mai.write = {direct = true, doc = "function(handle:number, value:string):boolean -- Writes the specified data to an open file descriptor with the specified handle."}
function obj.write(handle, value)
cprint("filesystem.write", handle, value)
compCheckArg(1,handle,"number")
@ -142,7 +142,7 @@ function obj.remove(path)
return elsa.filesystem.remove(directory .. "/" .. path)
end
mai.size = {doc = "function(path:string):number -- Returns the size of the object at the specified absolute path in the file system."}
mai.size = {direct = true, doc = "function(path:string):number -- Returns the size of the object at the specified absolute path in the file system."}
function obj.size(path)
cprint("filesystem.size", path)
compCheckArg(1,path,"string")
@ -153,7 +153,7 @@ function obj.size(path)
return elsa.filesystem.getSize(directory .. "/" .. path) or 0
end
mai.seek = {doc = "function(handle:number, whence:string, offset:number):number -- Seeks in an open file descriptor with the specified handle. Returns the new pointer position."}
mai.seek = {direct = true, doc = "function(handle:number, whence:string, offset:number):number -- Seeks in an open file descriptor with the specified handle. Returns the new pointer position."}
function obj.seek(handle, whence, offset)
--TODO
cprint("filesystem.seek", handle, whence, offset)
@ -166,14 +166,14 @@ function obj.seek(handle, whence, offset)
return handles[handle][1]:seek(whence, offset)
end
mai.spaceTotal = {doc = "function():number -- The overall capacity of the file system, in bytes."}
mai.spaceTotal = {direct = true, doc = "function():number -- The overall capacity of the file system, in bytes."}
function obj.spaceTotal()
--STUB
cprint("filesystem.spaceTotal")
return math.huge
end
mai.getLabel = {doc = "function():string -- Get the current label of the file system."}
mai.getLabel = {direct = true, doc = "function():string -- Get the current label of the file system."}
function obj.getLabel()
cprint("filesystem.getLabel")
return label
@ -190,7 +190,7 @@ function obj.setLabel(value)
label = value:sub(1,16)
end
mai.open = {doc = "function(path:string[, mode:string='r']):number -- Opens a new file descriptor and returns its handle."}
mai.open = {direct = true, doc = "function(path:string[, mode:string='r']):number -- Opens a new file descriptor and returns its handle."}
function obj.open(path, mode)
cprint("filesystem.open", path, mode)
if mode == nil then mode = "r" end
@ -220,7 +220,7 @@ function obj.open(path, mode)
end
end
mai.exists = {doc = "function(path:string):boolean -- Returns whether an object exists at the specified absolute path in the file system."}
mai.exists = {direct = true, doc = "function(path:string):boolean -- Returns whether an object exists at the specified absolute path in the file system."}
function obj.exists(path)
cprint("filesystem.exists", path)
compCheckArg(1,path,"string")
@ -256,13 +256,13 @@ function obj.list(path)
return list
end
mai.isReadOnly = {doc = "function():boolean -- Returns whether the file system is read-only."}
mai.isReadOnly = {direct = true, doc = "function():boolean -- Returns whether the file system is read-only."}
function obj.isReadOnly()
cprint("filesystem.isReadOnly")
return readonly
end
mai.makeDirectory = {doc = "function(path:string):boolean -- Creates a directory at the specified absolute path in the file system. Creates parent directories, if necessary."}
mai.makeDirectory = {direct = true, doc = "function(path:string):boolean -- Creates a directory at the specified absolute path in the file system. Creates parent directories, if necessary."}
function obj.makeDirectory(path)
cprint("filesystem.makeDirectory", path)
compCheckArg(1,path,"string")
@ -276,7 +276,7 @@ function obj.makeDirectory(path)
return elsa.filesystem.createDirectory(directory .. "/" .. path)
end
mai.isDirectory = {doc = "function(path:string):boolean -- Returns whether the object at the specified absolute path in the file system is a directory."}
mai.isDirectory = {direct = true, doc = "function(path:string):boolean -- Returns whether the object at the specified absolute path in the file system is a directory."}
function obj.isDirectory(path)
cprint("filesystem.isDirectory", path)
compCheckArg(1,path,"string")

View File

@ -27,7 +27,7 @@ function obj.bind(address)
bindaddress = address
end
mai.getForeground = {doc = "function():number, boolean -- Get the current foreground color and whether it's from the palette or not."}
mai.getForeground = {direct = true, doc = "function():number, boolean -- Get the current foreground color and whether it's from the palette or not."}
function obj.getForeground()
cprint("gpu.getForeground")
if bindaddress == nil then
@ -37,7 +37,7 @@ function obj.getForeground()
end
mai.setForeground = {doc = "function(value:number[, palette:boolean]):number, number or nil -- Sets the foreground color to the specified value. Optionally takes an explicit palette index. Returns the old value and if it was from the palette its palette index."}
mai.setForeground = {direct = true, doc = "function(value:number[, palette:boolean]):number, number or nil -- Sets the foreground color to the specified value. Optionally takes an explicit palette index. Returns the old value and if it was from the palette its palette index."}
function obj.setForeground(value, palette)
cprint("gpu.setForeground", value, palette)
compCheckArg(1,value,"number")
@ -54,7 +54,7 @@ function obj.setForeground(value, palette)
return component.cecinvoke(bindaddress, "setForeground", value, palette)
end
mai.getBackground = {doc = "function():number, boolean -- Get the current background color and whether it's from the palette or not."}
mai.getBackground = {direct = true, doc = "function():number, boolean -- Get the current background color and whether it's from the palette or not."}
function obj.getBackground()
cprint("gpu.getBackground")
if bindaddress == nil then
@ -63,7 +63,7 @@ function obj.getBackground()
return component.cecinvoke(bindaddress, "getBackground")
end
mai.setBackground = {doc = "function(value:number[, palette:boolean]):number, number or nil -- Sets the background color to the specified value. Optionally takes an explicit palette index. Returns the old value and if it was from the palette its palette index."}
mai.setBackground = {direct = true, doc = "function(value:number[, palette:boolean]):number, number or nil -- Sets the background color to the specified value. Optionally takes an explicit palette index. Returns the old value and if it was from the palette its palette index."}
function obj.setBackground(value, palette)
cprint("gpu.setBackground", value, palette)
compCheckArg(1,value,"number")
@ -81,7 +81,7 @@ function obj.setBackground(value, palette)
return component.cecinvoke(bindaddress, "setBackground", value, palette)
end
mai.getDepth = {doc = "function():number -- Returns the currently set color depth."}
mai.getDepth = {direct = true, doc = "function():number -- Returns the currently set color depth."}
function obj.getDepth()
cprint("gpu.getDepth")
return depthTbl[component.cecinvoke(bindaddress, "getDepth")]
@ -104,13 +104,13 @@ function obj.setDepth(depth)
return old
end
mai.maxDepth = {doc = "function():number -- Get the maximum supported color depth."}
mai.maxDepth = {direct = true, doc = "function():number -- Get the maximum supported color depth."}
function obj.maxDepth()
cprint("gpu.maxDepth")
return depthTbl[math.min(component.cecinvoke(bindaddress, "maxDepth"), maxtier)]
end
mai.fill = {doc = "function(x:number, y:number, width:number, height:number, char:string):boolean -- Fills a portion of the screen at the specified position with the specified size with the specified character."}
mai.fill = {direct = true, doc = "function(x:number, y:number, width:number, height:number, char:string):boolean -- Fills a portion of the screen at the specified position with the specified size with the specified character."}
function obj.fill(x, y, width, height, char)
cprint("gpu.fill", x, y, width, height, char)
compCheckArg(1,x,"number")
@ -127,13 +127,13 @@ function obj.fill(x, y, width, height, char)
return component.cecinvoke(bindaddress, "fill", x, y, width, height, char)
end
mai.getScreen = {doc = "function():string -- Get the address of the screen the GPU is currently bound to."}
mai.getScreen = {direct = true, doc = "function():string -- Get the address of the screen the GPU is currently bound to."}
function obj.getScreen()
cprint("gpu.getScreen")
return bindaddress
end
mai.getResolution = {doc = "function():number, number -- Get the current screen resolution."}
mai.getResolution = {direct = true, doc = "function():number, number -- Get the current screen resolution."}
function obj.getResolution()
cprint("gpu.getResolution")
if bindaddress == nil then
@ -158,7 +158,7 @@ function obj.setResolution(width, height)
return component.cecinvoke(bindaddress, "setResolution", width, height)
end
mai.maxResolution = {doc = "function():number, number -- Get the maximum screen resolution."}
mai.maxResolution = {direct = true, doc = "function():number, number -- Get the maximum screen resolution."}
function obj.maxResolution()
cprint("gpu.maxResolution")
if bindaddress == nil then
@ -169,7 +169,7 @@ function obj.maxResolution()
end
--STUB: Actually Implement viewport
mai.getViewport = {doc = "function():number, number -- Get the current viewport resolution."}
mai.getViewport = {direct = true, doc = "function():number, number -- Get the current viewport resolution."}
function obj.getViewport()
cprint("gpu.getViewport")
if bindaddress == nil then
@ -195,7 +195,7 @@ function obj.setViewport(width, height)
return component.cecinvoke(bindaddress, "setResolution", width, height)
end
mai.getPaletteColor = {doc = "function(index:number):number -- Get the palette color at the specified palette index."}
mai.getPaletteColor = {direct = true, doc = "function(index:number):number -- Get the palette color at the specified palette index."}
function obj.getPaletteColor(index)
cprint("gpu.getPaletteColor", index)
compCheckArg(1,index,"number")
@ -212,7 +212,7 @@ function obj.getPaletteColor(index)
return component.cecinvoke(bindaddress, "getPaletteColor", index)
end
mai.setPaletteColor = {doc = "function(index:number, color:number):number -- Set the palette color at the specified palette index. Returns the previous value."}
mai.setPaletteColor = {direct = true, doc = "function(index:number, color:number):number -- Set the palette color at the specified palette index. Returns the previous value."}
function obj.setPaletteColor(index, color)
cprint("gpu.setPaletteColor", index, color)
compCheckArg(1,index,"number")
@ -230,7 +230,7 @@ function obj.setPaletteColor(index, color)
return component.cecinvoke(bindaddress, "setPaletteColor", index, color)
end
mai.get = {doc = "function(x:number, y:number):string, number, number, number or nil, number or nil -- Get the value displayed on the screen at the specified index, as well as the foreground and background color. If the foreground or background is from the palette, returns the palette indices as fourth and fifth results, else nil, respectively."}
mai.get = {direct = true, doc = "function(x:number, y:number):string, number, number, number or nil, number or nil -- Get the value displayed on the screen at the specified index, as well as the foreground and background color. If the foreground or background is from the palette, returns the palette indices as fourth and fifth results, else nil, respectively."}
function obj.get(x, y)
cprint("gpu.get", x, y)
compCheckArg(1,x,"number")
@ -245,7 +245,7 @@ function obj.get(x, y)
return component.cecinvoke(bindaddress, "get", x, y)
end
mai.set = {doc = "function(x:number, y:number, value:string[, vertical:boolean]):boolean -- Plots a string value to the screen at the specified position. Optionally writes the string vertically."}
mai.set = {direct = true, doc = "function(x:number, y:number, value:string[, vertical:boolean]):boolean -- Plots a string value to the screen at the specified position. Optionally writes the string vertically."}
function obj.set(x, y, value, vertical)
cprint("gpu.set", x, y, value, vertical)
compCheckArg(1,x,"number")
@ -258,7 +258,7 @@ function obj.set(x, y, value, vertical)
return component.cecinvoke(bindaddress, "set", x, y, value, vertical)
end
mai.copy = {doc = "function(x:number, y:number, width:number, height:number, tx:number, ty:number):boolean -- Copies a portion of the screen from the specified location with the specified size by the specified translation."}
mai.copy = {direct = true, doc = "function(x:number, y:number, width:number, height:number, tx:number, ty:number):boolean -- Copies a portion of the screen from the specified location with the specified size by the specified translation."}
function obj.copy(x, y, width, height, tx, ty)
cprint("gpu.copy", x, y, width, height, tx, ty)
compCheckArg(1,x,"number")

View File

@ -32,13 +32,13 @@ local function checkUri(address, port)
error("address could not be parsed or no valid port given",4)
end
mai.isTcpEnabled = {doc = "function():boolean -- Returns whether TCP connections can be made (config setting)."}
mai.isTcpEnabled = {direct = true, doc = "function():boolean -- Returns whether TCP connections can be made (config setting)."}
function obj.isTcpEnabled()
cprint("internet.isTcpEnabled")
return settings.tcpEnabled
end
mai.isHttpEnabled = {doc = "function():boolean -- Returns whether HTTP requests can be made (config setting)."}
mai.isHttpEnabled = {direct = true, doc = "function():boolean -- Returns whether HTTP requests can be made (config setting)."}
function obj.isHttpEnabled()
cprint("internet.isHttpEnabled")
return settings.httpEnabled

View File

@ -437,7 +437,7 @@ function obj.send(address, port, ...)
return true
end
mai.getWakeMessage = {doc = "function():string -- Get the current wake-up message."}
mai.getWakeMessage = {direct = true, doc = "function():string -- Get the current wake-up message."}
function obj.getWakeMessage()
return wakeMessage
end
@ -471,13 +471,13 @@ function obj.close(port)
return true
end
mai.maxPacketSize = {doc = "function():number -- Gets the maximum packet size (config setting)."}
mai.maxPacketSize = {direct = true, doc = "function():number -- Gets the maximum packet size (config setting)."}
function obj.maxPacketSize()
return settings.maxNetworkPacketSize
end
if wireless then
mai.getStrength = {doc = "function():number -- Get the signal strength (range) used when sending messages."}
mai.getStrength = {direct = true, doc = "function():number -- Get the signal strength (range) used when sending messages."}
function obj.getStrength()
return strength
end
@ -489,7 +489,7 @@ if wireless then
end
end
mai.isOpen = {doc = "function(port:number):boolean -- Whether the specified port is open."}
mai.isOpen = {direct = true, doc = "function(port:number):boolean -- Whether the specified port is open."}
function obj.isOpen(port)
compCheckArg(1,port,"number")
return modem_host.open_ports[port] ~= nil
@ -515,7 +515,7 @@ function obj.open(port)
return true
end
mai.isWireless = {doc = "function():boolean -- Whether this is a wireless network card."}
mai.isWireless = {direct = true, doc = "function():boolean -- Whether this is a wireless network card."}
function obj.isWireless()
return wireless
end

View File

@ -14,6 +14,7 @@ end
local mai = {}
local obj = {}
mai.connect = {direct = true, doc = "function(kind:string, address:string or number or nil, slot:number or nil, ...):boolean -- Attach a component to the emulator."}
function obj.connect(kind, address, slot, ...)
cprint("ocemu.connect", kind, address, slot, ...)
compCheckArg(1,kind,"string")
@ -30,12 +31,14 @@ function obj.connect(kind, address, slot, ...)
return component.connect(kind, address, slot, ...)
end
mai.disconnect = {direct = true, doc = "function(address:string):boolean -- Remove a component from the emulator."}
function obj.disconnect(address)
cprint("ocemu.disconnect", address)
compCheckArg(1,address,"string")
return component.disconnect(address)
end
mai.lootlist = {direct = true, doc = "function():table -- Get a list of loot disks and disk information."}
function obj.lootlist()
cprint("ocemu.lootlist")
local info={}
@ -59,6 +62,7 @@ function obj.lootlist()
return dirs
end
mai.lootinsert = {direct = true, doc = "function(name:string):boolean or nil, string -- Insert a loot disk into the computer."}
function obj.lootinsert(name)
cprint("ocemu.lootinsert", name)
compCheckArg(1,name,"string")
@ -82,6 +86,7 @@ function obj.lootinsert(name)
return true
end
mai.lootremove = {direct = true, doc = "function(name:string):boolean or nil, string -- Remove a loot disk from the computer."}
function obj.lootremove(name)
cprint("ocemu.lootremove", name)
compCheckArg(1,name,"string")
@ -103,6 +108,7 @@ function obj.lootremove(name)
return true
end
mai.lootattached = {direct = true, doc = "function(name:string):boolean or nil, string -- Check if a loot disk is inserted in the computer."}
function obj.lootattached(name)
cprint("ocemu.lootattached", name)
compCheckArg(1,name,"string")
@ -117,10 +123,12 @@ function obj.lootattached(name)
return false
end
mai.biglist = {direct = true, doc = "function() -- Generate a giant useless list of lua information from the computer."}
function obj.biglist()
machine.biglistgen=true
end
mai.log = {direct = true, doc = "function(...) -- Output a message to the emulator's stdout."}
function obj.log(...)
print(...)
end