Advertisement
Guest User

ini_extensions.script (2)

a guest
Aug 9th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.95 KB | None | 0 0
  1. local override_ini_getters = { "r_bool", "r_float", "r_clsid", "r_s32", "r_token", "r_vector", "r_u32", "r_string_wq", "r_string" }
  2.  
  3. function add_safe_getters(target)
  4.     target.line_exist_safe = function(ini, section, line)
  5.         return ini:section_exist(section) and ini:line_exist(section, line)
  6.     end
  7.     for fi, k in ipairs(override_ini_getters) do
  8.         target[k.."_safe"] = function(ini, section, line, ...)
  9.             if ini:line_exist_safe(section, line) then
  10.                 return ini[k](ini, section, line, ...)
  11.             end
  12.             return nil
  13.         end
  14.     end
  15. end
  16.  
  17. local ini_table = {
  18. ["system.ltx"] = system_ini(),
  19. ["game.ltx"] = game_ini()
  20. }
  21.  
  22. add_safe_getters(ini_file)
  23. add_safe_getters(ini_table["system.ltx"])
  24. add_safe_getters(ini_table["game.ltx"])
  25.  
  26. __ini_file = ini_file
  27. ini_file = function(file_name)
  28.     local result_file = ini_table[file_name]
  29.     if not result_file then
  30.         result_file = __ini_file(file_name)
  31.         ini_table[file_name] = result_file
  32.     end
  33.     return result_file
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement