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

Method SetMetaTable

lua.go:1150–1165  ·  view source on GitHub ↗

SetMetaTable pops a table from the stack and sets it as the new metatable for the value at index. http://www.lua.org/manual/5.2/manual.html#lua_setmetatable

(index int)

Source from the content-addressed store, hash-verified

1148//
1149// http://www.lua.org/manual/5.2/manual.html#lua_setmetatable
1150func (l *State) SetMetaTable(index int) {
1151 l.checkElementCount(1)
1152 mt, ok := l.stack[l.top-1].(*table)
1153 if apiCheck && !ok && l.stack[l.top-1] != nil {
1154 panic("table expected")
1155 }
1156 switch v := l.indexToValue(index).(type) {
1157 case *table:
1158 v.metaTable = mt
1159 case *userData:
1160 v.metaTable = mt
1161 default:
1162 l.global.metaTables[l.TypeOf(index)] = mt
1163 }
1164 l.top--
1165}
1166
1167// Error generates a Lua error. The error message must be on the stack top.
1168// The error can be any of any Lua type. This function will panic().

Callers 4

debug.goFile · 0.80
base.goFile · 0.80
StringOpenFunction · 0.80
SetMetaTableNamedFunction · 0.80

Calls 3

checkElementCountMethod · 0.95
indexToValueMethod · 0.95
TypeOfMethod · 0.95

Tested by

no test coverage detected