ModerkaScripts

configparser [Configuration Parser]

Jun 16th, 2024
693
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.96 KB | None | 0 0
  1. --[[
  2.     configparser
  3.     Configuration Parser
  4.     twix.cyou/pix
  5.  
  6.     Author: ttwiz_z (ttwizz)
  7.     License: MIT
  8.     GitHub: https://github.com/ttwizz/configparser
  9. ]]
  10.  
  11.  
  12. return function(Input, Output)
  13.     assert(type(Input) == "string", "Argument 1 (Input) must be a string")
  14.  
  15.     Output = type(Output) == "table" and Output or {}
  16.  
  17.     for Key, Value in string.gmatch(Input, "%s*(.-)%s*:%s*(.-)%s*\n") do
  18.         if string.lower(Value) == "nil" or string.lower(Value) == "null" or string.lower(Value) == "none" or string.lower(Value) == "nothing" or string.lower(Value) == "undefined" then
  19.             Output[Key] = nil
  20.         elseif string.lower(Value) == "true" then
  21.             Output[Key] = true
  22.         elseif string.lower(Value) == "false" then
  23.             Output[Key] = false
  24.         elseif tonumber(Value) then
  25.             Output[Key] = tonumber(Value)
  26.         else
  27.             Output[Key] = Value
  28.         end
  29.     end
  30.  
  31.     return Output
  32. end
Advertisement
Add Comment
Please, Sign In to add comment