Posted 29 May 2014 - 10:58 AM
                I've been working on this for far too long, so I've decided to ask for help.
I'd like to wrap all the functions that deal with paths they return modified values. I'd also like this to affect all further operations on the computer. (I need it to work with user supplied code, like an OS)
For example, if a program calls shell.run('/bar.lua'), I'd like it to actually run /foo/bar.lua
I've tried stuff like:
Any tips?
                
            I'd like to wrap all the functions that deal with paths they return modified values. I'd also like this to affect all further operations on the computer. (I need it to work with user supplied code, like an OS)
For example, if a program calls shell.run('/bar.lua'), I'd like it to actually run /foo/bar.lua
I've tried stuff like:
local root = '/foo/'
local oldShell = shell
local wrap(...)
  local tArg = {...}
  local tOut = {}
  for k,v in ipairs(tArg) do
	if type(v) == "string" then
	  if v=="." then
		tOut[k] = root
	  else
		tOut[k] = root..v
	  end
	else
	  error('Expected string, got '..type(v))
	end
  end
  return unpack(tOut)
end
function shell.run(command, ...)
  return oldShell.run(wrap(command), ...)
end
-- repeat for all api functions that use paths
but it doesn't seem to work correctly.Any tips?