qaisjp

Test for mtasa-blue #9210 (server only)

Apr 7th, 2016
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.95 KB | None | 0 0
  1. -- Test for new toJSON pretty types
  2. -- see https://bugs.mtasa.com/view.php?id=9210
  3. -- and https://github.com/multitheftauto/mtasa-blue/commit/9b34a0cf6055b74a4533e0bc78bb0fbe16fe53db
  4.  
  5. -- server.lua
  6. local display, text
  7. local tab = {
  8.     "Hello there",
  9.     {
  10.         "Here is a nested table...",
  11.         with = "a key!",
  12.     },
  13.     math.pi,
  14.     1.1,
  15.     1,
  16.     1.0 -- shouldn't make a difference
  17. }
  18.  
  19. addEventHandler("onResourceStart", resourceRoot, function()
  20.         display = TextDisplay()
  21.         text = TextItem("Hello world!", 0.3, 0.8 )
  22.         display:addText(text)
  23.     end
  24. )      
  25.  
  26. addCommandHandler("json", function(player, _, ...)
  27.         local args = {}
  28.         for i, v in ipairs{...} do
  29.             if (v == "true") or (v == "false") then
  30.                 v = v == "true"
  31.             elseif tonumber(v) then
  32.                 v = tonumber(v)
  33.             elseif v == "nil" then
  34.                 v = nil
  35.             end
  36.             args[i] = v
  37.         end
  38.  
  39.         display:addObserver(player)
  40.         local json = toJSON(tab, unpack(args))
  41.         if json then
  42.             text:setText(json)
  43.         end
  44.     end
  45. )
Add Comment
Please, Sign In to add comment