Skip to content

Commit

Permalink
updated storage and added prismaError
Browse files Browse the repository at this point in the history
  • Loading branch information
Lonaasan committed Oct 23, 2024
1 parent da476ce commit a2b9c1c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
18 changes: 17 additions & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ std = {
std = {},
neon = {},
starExtensions = {},
prismaError = {
fields = {
throw = {}
}
},
prismaStorage = {
fields = {
get = {},
Expand Down Expand Up @@ -380,7 +385,18 @@ std = {
bridge = {}
}
},
storage = {}
storage = {
fields = {
get = {},
post = {},
put = {},
delete = {},
clear = {},
getAll = {},
exists = {}
}
},
error = {}
}
},
gsub = {},
Expand Down
9 changes: 1 addition & 8 deletions Prisma/prisma/api/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ string.prisma.api.mods = string.prisma.api.mods or {};

prismaAPI = {};

-- local prismaAPIStorage = {};

function prismaAPI.registerMods()
for modName, mod in pairs(string.prisma.api.mods) do
if not prismaStorage.exists(modName) then
string.prisma.debug.log.info("Registering mod: " .. modName);
string.prisma.debug.log.info("Mod: " .. mod);
prismaStorage.post(modName, mod);
end
-- prismaAPIStorage[modName] = mod;
end
end

Expand All @@ -26,8 +23,4 @@ function prismaAPI.getMods()
string.prisma.debug.log.info("Key: " .. key);
string.prisma.debug.log.info("Value: " .. value);
end
-- or modName, mod in pairs(prismaAPIStorage) do
-- string.prisma.debug.log.info("Stored mod: " .. modName);
-- string.prisma.debug.log.info("Mod: " .. mod);
-- end
end
end
14 changes: 14 additions & 0 deletions Prisma/prisma/error/error.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---Prisma Error | https://github.com/Lonaasan/Prisma/blob/main/Prisma/prisma/error/error.lua
---Author: Lonaasan
string.prisma = string.prisma or {};
string.prisma.error = string.prisma.error or {};

prismaError = {};

function prismaError.throw(errorMessage, errorLevel)
errorLevel = errorLevel or 3;
error(errorMessage, errorLevel);
end

--- Export the functions for 3rd parties to use without the possibility of changing the original code
string.prisma.error = prismaError;
15 changes: 8 additions & 7 deletions Prisma/prisma/storage/storage.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---Prisma Storage | https://github.com/Lonaasan/Prisma/blob/main/Prisma/prisma/storage/storage.lua
---Author: Lonaasan
require("/prisma/error/error.lua");

string.prisma = string.prisma or {};
string.prisma.storage = string.prisma.storage or {};
Expand All @@ -10,34 +11,34 @@ storage = storage or {};

function prismaStorage.get(key)
if storage[key] == nil then
error("Key does not exist", 2);
prismaError.throw("Key does not exist");
end
return storage[key];
end

function prismaStorage.post(key, value)
if not key or not value then
error("Key or value is nil", 2);
prismaError.throw("Key or value is nil");
end
if storage[key] then
error("Key already exists", 2);
prismaError.throw("Key already exists");
end
storage[key] = value;
end

function prismaStorage.put(key, value)
if not key or not value then
error("Key or value is nil", 2);
prismaError.throw("Key or value is nil");
end
if storage[key] == nil then
error("Key does not exist", 2);
prismaError.throw("Key does not exist");
end
storage[key] = value;
end

function prismaStorage.delete(key)
if storage[key] == nil then
error("Key does not exist", 2);
prismaError.throw("Key does not exist");
end
storage[key] = nil;
end
Expand All @@ -55,4 +56,4 @@ function prismaStorage.exists(key)
end

--- Export the functions for 3rd parties to use without the possibility of changing the original code
string.prisma.storage = prismaStorage;
string.prisma.storage = prismaStorage;

0 comments on commit a2b9c1c

Please sign in to comment.