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

Function SetUpValue

lua.go:1278–1289  ·  view source on GitHub ↗

SetUpValue sets the value of a closure's upvalue. It assigns the value at the top of the stack to the upvalue and returns its name. It also pops a value from the stack. function and index are as in UpValue. Returns an empty string and false if the index is greater than the number of upvalues. htt

(l *State, function, index int)

Source from the content-addressed store, hash-verified

1276//
1277// http://www.lua.org/manual/5.2/manual.html#lua_setupvalue
1278func SetUpValue(l *State, function, index int) (name string, ok bool) {
1279 if c, isClosure := l.indexToValue(function).(closure); isClosure {
1280 if ok = 1 <= index && index <= c.upValueCount(); ok {
1281 if c, isLua := c.(*luaClosure); isLua {
1282 name = c.prototype.upValues[index-1].name
1283 }
1284 l.top--
1285 c.setUpValue(index-1, l.stack[l.top])
1286 }
1287 }
1288 return
1289}
1290
1291func (l *State) upValue(f, n int) **upValue {
1292 return &l.indexToValue(f).(*luaClosure).upValues[n-1]

Callers 1

loadHelperFunction · 0.85

Calls 3

indexToValueMethod · 0.80
upValueCountMethod · 0.65
setUpValueMethod · 0.65

Tested by

no test coverage detected