Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Test for new toJSON pretty types
- -- see https://bugs.mtasa.com/view.php?id=9210
- -- and https://github.com/multitheftauto/mtasa-blue/commit/9b34a0cf6055b74a4533e0bc78bb0fbe16fe53db
- -- server.lua
- local display, text
- local tab = {
- "Hello there",
- {
- "Here is a nested table...",
- with = "a key!",
- },
- math.pi,
- 1.1,
- 1,
- 1.0 -- shouldn't make a difference
- }
- addEventHandler("onResourceStart", resourceRoot, function()
- display = TextDisplay()
- text = TextItem("Hello world!", 0.3, 0.8 )
- display:addText(text)
- end
- )
- addCommandHandler("json", function(player, _, ...)
- local args = {}
- for i, v in ipairs{...} do
- if (v == "true") or (v == "false") then
- v = v == "true"
- elseif tonumber(v) then
- v = tonumber(v)
- elseif v == "nil" then
- v = nil
- end
- args[i] = v
- end
- display:addObserver(player)
- local json = toJSON(tab, unpack(args))
- if json then
- text:setText(json)
- end
- end
- )
Add Comment
Please, Sign In to add comment