--Provides an interface to store data in a database of some kind --[[ Uses: GM.StorageMethod Can be: "Text", "Static Map", "LZWCompressed" If method is "Static Map", then GM.StoreageStaticMap must be a table of strings to string ID's. GM.StorageBackend Can be: "File" GM.StorageDebug Can be: true, false Enables extra debugging to find errors easily ]] print("Hello from database.lua!") function loadTable(uniqueIdentifier) return nil end function storeTable(uniqueIdentifier, table) if (GM.StorageDebug) then print("Asked to store:") PrintTable(table) end if (GM.StorageDebug) then for k,v in pairs(tbl) do if (isfunction(v)) then print("Database.lua error: tried to save a table that has a function in it!") PrintTable(tbl) print("At field:") print(k) end end end end --Remove symbols that might be used as part of the storage scheme local function encodeSymbolic(mstring) local replacements = { {"\\", "\\\\"}, {"{","\\{"}, {"}","\\}"}, {"(","\\("}, {")","\\)"}, } local ostring = mstring for k,v in pairs(replacements) do ostring = string.Replace(ostring,v[1],v[2]) end end local function convertTableText(tbl) local output = "t(" local function addtoout(k) if (istable(k)) then output = output .. convertTableText(k) elseif (isstring(k)) then output = output .. "s(" .. encodeSymbolic(k) .. ")" elseif (isnumber(k)) then output = output .. "n(" .. k .. ")" elseif (isbool(k)) then if (k) then output = output .. "b(true)" else output = output .. "b(false)" end elseif (isangle(k)) then output = output .. "a(" .. k.p .. "," .. k.y .. "," .. k.r .. ")" elseif (isvector(k)) then output = output .. "v(" .. k.x .. "," .. k.y .. "," .. k.z .. ")" else assert(true,"Tried to store unknown value type:") printi(k) end end for k,v in pairs(tbl) do addtoout(k) output = output .. ":" addtoout(v) end output = output .. ")" end --[[ local function convertTableStatic(tbl) if (GM.StorageStaticMap == nil) then print("---------ERROR: database.lua-----------") print("\tGM.StorageMethod is set to \"Static Map\", but GM.StoreageStaticMap is not defined!") return end end local function convertTableCompressed(tbl) end local function parseStaticTable(tbl) end --]]