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)
| 221 | // calls the corresponding metamethod with the value as argument, and uses |
| 222 | // the result of the call as its result. |
| 223 | func 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 |
no test coverage detected