×

Langue

Fermer
Atelier 801
  • Forums
  • Dev Tracker
  • Connexion
    • English Français
      Português do Brasil Español
      Türkçe Polski
      Magyar Română
      العربية Skandinavisk
      Nederlands Deutsch
      Bahasa Indonesia Русский
      中文 Filipino
      Lietuvių kalba 日本語
      Suomi עברית
      Italiano Česky
      Hrvatski Slovensky
      Български Latviešu
      Estonian
  • Langue
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • Prettyprint for lua
Prettyprint for lua
King_seniru
« Censeur »
1605160320000
    • King_seniru#5890
    • Profil
    • Derniers messages
    • Tribu
#1
  8
Ever wasted your time wondering if x is a number or string? Or the type of x is boolean or not defined at all? Here I made a useful tool to avoid all of such confusions.

Prettyprint for transformice lua is a influenced by node's and luvit's prettyprint - so it is really pretty!

Please send the +1 if I advertised this really good


To use this paste this small snippet on top of your code and follow the documentation presented below. The code can be found here

Documentation a dit :


prettyprint ( object, options )

    Outputs the prettified result
    • object (any) - The input object (could be a string, number, boolean, function, table or nil)
    • options (table|nil) - Extra options passed as defined below (default = { })
      • options.maxDepth (number|nil) - Maximum depth to reach if it's a table. In other words it will stop transversing further after that limit (default = 30)
      • options.truncateAt (number|nil) - The maximum amount of values printed before truncating (default = 30)




p ( object, options )

    Alias to prettyprint

Few examples

Code Lua

1
2
3
4
5
6
p("Hello world")
p(true)
p(42)
p(print)
p({1, 2, 3, 4, 5})
p(undefinedVariable)
Output:

a dit :

"Hello world"
true
42
function: 6ca19a35
{ 1, 2, 3, 4, 5 }
nil

Code Lua

1
p(tfm.get.room) -- a table
Output:
a dit :

{ passwordProtected: false,
    uniquePlayers: 1,
    maxPlayers: 50,
    community: "xx",
    mirroredMap: false,
    isTribeHouse: false,
    currentMap: "0",
    language: "int",
    objectList: { },
    name: "*#lua",
      playerList: { King_seniru#5890: { isJumping: false,
      isShaman: true,
      movingLeft: false,
      movingRight: false,
      vx: 0,
      isInvoking: false,
      cheeses: 0,
      title: 125,
      spouseName: "lightymouse#0421",
      look: "1;0,0,0,17,0,0,0,0,0",
      isVampire: false,
      gender: 2,
      vy: 0,
      playerName: "King_seniru#5890",
      inHardMode: 2,
      isDead: false,
      y: 179,
      x: 720,
      isFacingRight: true,
      tribeId: 1051168,
      id: 89818485,
      community: "en",
      language: "int",
      registrationDate: 1482900756347,
      spouseId: 75771821,
      tribeName: "We Talk A Lot",
      hasCheese: false,
      score: 0,
      shamanMode: 2 } } }


Code Lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
-- Pretty print with extra options
p({
foo = {
foo = "foo",
bar = nil,
baz = {
spam = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
ham = {
a = { true, false, true, false },
b = { true, false, false, true }
}
}
}
}, {
maxDepth = 4,
truncateAt = 6
})
Output:
a dit :

{ foo: { foo: "foo",
    baz: { ham: { a: table: 75c68dc6, b: table: 33b83c61 },
      spam: { 1,
        2,
        3,
        4,
        5,
        6,
        ... 4 more values } } } }


Extremq
« Citoyen »
1609017300000
    • Extremq#0000
    • Profil
    • Derniers messages
    • Tribu
#2
  1
This is EXTREMELY useful. Everyone that is interested in Lua should know about this tool.
Gamedroit
« Citoyen »
1611405600000
    • Gamedroit#3347
    • Profil
    • Derniers messages
    • Tribu
#3
  1
Code Lua

1
2
3
4
5
6
7
8
local string_repeat = function(str, times)
local res = ""
while times > 0 do
res = res .. str
times = times - 1
end
return res
end
You can replace the above code with the native lua function: string.rep(string, count)
Code Lua

1
2
3
local str = "hello world!"
print(str:rep(3)) -- hello world!hello world!hello world!
print(string.rep(str, 3))
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • Prettyprint for lua
© Atelier801 2018

Equipe Conditions Générales d'Utilisation Politique de Confidentialité Contact

Version 1.27