MCPcopy Index your code
hub / github.com/Shopify/go-lua / ToStringMeta

Function ToStringMeta

auxiliary.go:223–241  ·  view source on GitHub ↗

ToStringMeta converts any Lua value at the given index to a Go string in a reasonable format. The resulting string is pushed onto the stack and also returned by the function. If the value has a metatable with a "__tostring" field, then ToStringMeta calls the corresponding metamethod with the value

(l *State, index int)

Source from the content-addressed store, hash-verified

221// calls the corresponding metamethod with the value as argument, and uses
222// the result of the call as its result.
223func ToStringMeta(l *State, index int) (string, bool) {
224 if !CallMeta(l, index, "__tostring") {
225 switch l.TypeOf(index) {
226 case TypeNumber, TypeString:
227 l.PushValue(index)
228 case TypeBoolean:
229 if l.ToBoolean(index) {
230 l.PushString("true")
231 } else {
232 l.PushString("false")
233 }
234 case TypeNil:
235 l.PushString("nil")
236 default:
237 l.PushFString("%s: %p", TypeNameOf(l, index), l.ToValue(index))
238 }
239 }
240 return l.ToString(-1)
241}
242
243// NewMetaTable returns false if the registry already has the key name. Otherwise,
244// creates a new table to be used as a metatable for userdata, adds it to the

Callers 2

base.goFile · 0.85
formatHelperFunction · 0.85

Calls 9

CallMetaFunction · 0.85
TypeNameOfFunction · 0.85
TypeOfMethod · 0.80
PushValueMethod · 0.80
ToBooleanMethod · 0.80
PushStringMethod · 0.80
PushFStringMethod · 0.80
ToValueMethod · 0.80
ToStringMethod · 0.80

Tested by

no test coverage detected