added io library isolation so logic functions cant access the io functions
This commit is contained in:
parent
f1013a2356
commit
94bb85c31d
@ -1,6 +1,4 @@
|
|||||||
|
|
||||||
require "utility"
|
|
||||||
|
|
||||||
GateDefinition = {
|
GateDefinition = {
|
||||||
ports = {},
|
ports = {},
|
||||||
logic = function(gate) end,
|
logic = function(gate) end,
|
||||||
|
22
sim/iosafe.lua
Normal file
22
sim/iosafe.lua
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
assert(not io.safe, "re-execution of iosafe")
|
||||||
|
|
||||||
|
local iosafe = io
|
||||||
|
_G.io = {safe = true}
|
||||||
|
local requiresafe = require
|
||||||
|
_G.require = nil
|
||||||
|
|
||||||
|
local savedir = OPT_SAVE_DIR
|
||||||
|
|
||||||
|
function io.open(fn, mode)
|
||||||
|
fn = fn:gsub("\\", "/")
|
||||||
|
assert(not fn:find("[^a-zA-Z0-9%._ ]"), "illegal character in file name \""..fn.."\"")
|
||||||
|
assert(not fn:find("%.%."), "illegal updir in file name \""..fn.."\"")
|
||||||
|
fn = fn:gsub("^/", "")
|
||||||
|
|
||||||
|
fn = savedir.."/"..fn
|
||||||
|
|
||||||
|
print("access file \""..fn.."\"")
|
||||||
|
|
||||||
|
return iosafe.open(fn, mode)
|
||||||
|
end
|
17
sim/main.lua
17
sim/main.lua
@ -1,8 +1,14 @@
|
|||||||
|
|
||||||
OPT_SAVE_DIR = arg[1] or error("must specify save location")
|
OPT_SAVE_DIR = arg[1] or error("must specify save location")
|
||||||
OPT_SAVE_DIR = OPT_SAVE_DIR:gsub("\\$", "").."\\"
|
OPT_SAVE_DIR = OPT_SAVE_DIR:gsub("\\", "/")
|
||||||
|
OPT_SAVE_DIR = OPT_SAVE_DIR:gsub("/$", "")
|
||||||
print("Save location set to \""..OPT_SAVE_DIR.."\"")
|
print("Save location set to \""..OPT_SAVE_DIR.."\"")
|
||||||
|
|
||||||
|
local socket = require("socket")
|
||||||
|
|
||||||
|
dofile("iosafe.lua")
|
||||||
|
|
||||||
|
dofile("utility.lua")
|
||||||
dofile("simulation.lua")
|
dofile("simulation.lua")
|
||||||
dofile("group.lua")
|
dofile("group.lua")
|
||||||
dofile("wire.lua")
|
dofile("wire.lua")
|
||||||
@ -104,7 +110,6 @@ local function acceptclient()
|
|||||||
print("Connection from " .. ip .. ":" .. port)
|
print("Connection from " .. ip .. ":" .. port)
|
||||||
end
|
end
|
||||||
|
|
||||||
local socket = require("socket")
|
|
||||||
server = assert(socket.bind("*", 25000))
|
server = assert(socket.bind("*", 25000))
|
||||||
client = nil
|
client = nil
|
||||||
|
|
||||||
@ -245,10 +250,12 @@ while 1 do
|
|||||||
if obj.logictype == 0 then
|
if obj.logictype == 0 then
|
||||||
local numportsi = 0; for k, wire in pairs(obj.group.in_ports ) do numportsi = numportsi+1 end
|
local numportsi = 0; for k, wire in pairs(obj.group.in_ports ) do numportsi = numportsi+1 end
|
||||||
local numportso = 0; for k, wire in pairs(obj.group.out_ports) do numportso = numportso+1 end
|
local numportso = 0; for k, wire in pairs(obj.group.out_ports) do numportso = numportso+1 end
|
||||||
|
local numwires = 0; for k, wire in pairs(obj.group.wires ) do numwires = numwires +1 end
|
||||||
|
|
||||||
info = "\\c5WIRE<br>" .. (obj.group.state and "\\c2ON" or "\\c0OFF") .. "\n" ..
|
info = "\\c5Net " .. tostring(obj.group):match("table: 0x(.+)"):upper() .. "\n" .. (obj.group.state and "\\c2On" or "\\c0Off") .. "\n" ..
|
||||||
"IN PORTS: " ..numportsi.."\n"..
|
"Wires: "..numwires.."\n"..
|
||||||
"OUT PORTS: "..numportso
|
"In Ports: " ..numportsi.."\n"..
|
||||||
|
"Out Ports: "..numportso
|
||||||
;
|
;
|
||||||
else
|
else
|
||||||
info = "\\c5" .. obj.definition.name .. "<br>"
|
info = "\\c5" .. obj.definition.name .. "<br>"
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
|
|
||||||
require "utility"
|
|
||||||
|
|
||||||
Simulation = {}
|
Simulation = {}
|
||||||
|
|
||||||
function Simulation:new()
|
function Simulation:new()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user