Function; print - HWRM/KarosGraveyard GitHub Wiki

print (<Element1>, <Element2>, ..., <ElementN>)

Description

(previously from LUA 4 Manual: 6.1 Basic Functions)
now at https://www.lua.org/manual/4.0/manual.html#print:

"Receives any number of arguments, and prints their values using the strings returned by tostring. This function is not intended for formatted output, but only as a quick way to show a value, for instance for debugging. See Section 6.4 for functions for formatted output."

Note that although print can handle any type of argument, Lua string concatenation cannot.

💡 The output from this function can be found in Homeworld/Bin/Release/HwRM.log.

Example

local t = {};
local n = 10;
local s = "hey";
print(t, n, s);
-- example output:
table: 0x559de0441ed0   10      hey

String concatenation will not work with values such as nil, so be careful when constructing strings to print:

local val = nil;
print("val is: " .. val); -- will error since val is `nil`
local val = nil;
print("val is: " .. (val or "nil")); -- ok

Arguments

<Element1> to <ElementN>: the elements to print. (may be any type of object; typically a string or string variable)

Related Functions

Function Reference

tostring

LUA 4 Manual: 6.1 Basic Functions

Comments

Page Status

Updated Formatting? Initial
Updated for HWRM? Initial

⚠️ **GitHub.com Fallback** ⚠️