summaryrefslogtreecommitdiff
path: root/indra/newview/scripts/lua/require/printf.lua
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2024-09-25 11:56:44 -0400
committerNat Goodspeed <nat@lindenlab.com>2024-09-25 11:56:44 -0400
commit55df7328c6f8c864ea309c57d73e791e079b3c2c (patch)
treecb4cba5e51d9649ba229c4eefeaafe783b9250e2 /indra/newview/scripts/lua/require/printf.lua
parent4b2b94f4864f2e2e7d76f4f17b2d58bb959b3edb (diff)
parent86d2fb93b73d2689104c564ec859be7f83416691 (diff)
Merge branch 'develop' into marchcat/xcode-16
Diffstat (limited to 'indra/newview/scripts/lua/require/printf.lua')
-rw-r--r--indra/newview/scripts/lua/require/printf.lua19
1 files changed, 19 insertions, 0 deletions
diff --git a/indra/newview/scripts/lua/require/printf.lua b/indra/newview/scripts/lua/require/printf.lua
new file mode 100644
index 0000000000..e84b2024df
--- /dev/null
+++ b/indra/newview/scripts/lua/require/printf.lua
@@ -0,0 +1,19 @@
+-- printf(...) is short for print(string.format(...))
+
+local inspect = require 'inspect'
+
+local function printf(format, ...)
+ -- string.format() only handles numbers and strings.
+ -- Convert anything else to string using the inspect module.
+ local args = {}
+ for _, arg in pairs(table.pack(...)) do
+ if type(arg) == 'number' or type(arg) == 'string' then
+ table.insert(args, arg)
+ else
+ table.insert(args, inspect(arg))
+ end
+ end
+ print(string.format(format, table.unpack(args)))
+end
+
+return printf