MCPcopy Index your code
hub / github.com/yuin/gopher-lua / ObjLen

Method ObjLen

state.go:1956–1973  ·  view source on GitHub ↗

* }}} */ * unary operations {{{ */

(v1 LValue)

Source from the content-addressed store, hash-verified

1954/* unary operations {{{ */
1955
1956func (ls *LState) ObjLen(v1 LValue) int {
1957 if v1.Type() == LTString {
1958 return len(string(v1.(LString)))
1959 }
1960 op := ls.metaOp1(v1, "__len")
1961 if op.Type() == LTFunction {
1962 ls.Push(op)
1963 ls.Push(v1)
1964 ls.Call(1, 1)
1965 ret := ls.reg.Pop()
1966 if ret.Type() == LTNumber {
1967 return int(ret.(LNumber))
1968 }
1969 } else if v1.Type() == LTTable {
1970 return v1.(*LTable).Len()
1971 }
1972 return 0
1973}
1974
1975/* }}} */
1976

Callers 1

TestObjLenFunction · 0.45

Calls 6

metaOp1Method · 0.95
PushMethod · 0.95
CallMethod · 0.95
TypeMethod · 0.65
PopMethod · 0.65
LenMethod · 0.45

Tested by 1

TestObjLenFunction · 0.36