hdjdhj
01-22-2008, 09:48 AM
I've created some functions which I would like to be able to share with different scripts. However, I can't figure out how to include those shared scripts. I tried using "require" and there's no compile time problem but at run time, the script can't be found...do I have to explicitly upload each extra script? That seems wrong.
How can I do the equivalent of a c-preprocessor style #include to pull in the source of another script at compile time?
P.S. Below is a hacky way to provide a function called ForceDirectories that will create all needed subfolders given a single path. I've only spent about 5 minutes with the scripting language so I'm sure this isn't the best way to do it, but people might find it handy. I'm sure I could have done it with a single function but I wanted to experiment with the associative arrays.
I would argue however that ForceDirectories should be a built-in action.
-- TrueUpdate missing a lot of convenience stuff so provide it ourselves
function SplitPathIntoTable(path)
local result = {};
local oldPath = path
local newPath = ""
local p = String.Find(oldPath, "\\")
while p > 0 do
local temp = String.Left(oldPath, p)
--newPath = newPath .. temp
Table.Insert(result, Table.Count(result) + 1, temp)
--Folder.Create(newPath)
oldPath = String.Mid(oldPath, p+1, -1)
p = String.Find(oldPath, "\\")
end
-- Get the tail end, if any
if String.Length(oldPath) > 0
then Table.Insert(result, Table.Count(result) + 1, oldPath .. "\\")
end
return result
end
function ForceDirectories(path)
local tree = SplitPathIntoTable(path)
local root = ""
for i, v in tree do
root = root .. v
if i > 1 -- Don't want the C: part forced
then
Folder.Create(root) -- Sigh, no FORCE DIRECTORY
end
end
return root
end
How can I do the equivalent of a c-preprocessor style #include to pull in the source of another script at compile time?
P.S. Below is a hacky way to provide a function called ForceDirectories that will create all needed subfolders given a single path. I've only spent about 5 minutes with the scripting language so I'm sure this isn't the best way to do it, but people might find it handy. I'm sure I could have done it with a single function but I wanted to experiment with the associative arrays.
I would argue however that ForceDirectories should be a built-in action.
-- TrueUpdate missing a lot of convenience stuff so provide it ourselves
function SplitPathIntoTable(path)
local result = {};
local oldPath = path
local newPath = ""
local p = String.Find(oldPath, "\\")
while p > 0 do
local temp = String.Left(oldPath, p)
--newPath = newPath .. temp
Table.Insert(result, Table.Count(result) + 1, temp)
--Folder.Create(newPath)
oldPath = String.Mid(oldPath, p+1, -1)
p = String.Find(oldPath, "\\")
end
-- Get the tail end, if any
if String.Length(oldPath) > 0
then Table.Insert(result, Table.Count(result) + 1, oldPath .. "\\")
end
return result
end
function ForceDirectories(path)
local tree = SplitPathIntoTable(path)
local root = ""
for i, v in tree do
root = root .. v
if i > 1 -- Don't want the C: part forced
then
Folder.Create(root) -- Sigh, no FORCE DIRECTORY
end
end
return root
end