github.com/arnodel/golua@v0.0.0-20230215163904-e0b5347eaaa1/ast/functionstat.go (about) 1 package ast 2 3 // NewFunctionStat returns an AssgnStat, ie. "function f() ..." gets transformed 4 // to "f = function() ...". This is a shortcut, probably should make a specific 5 // node for this. 6 func NewFunctionStat(fName Var, method Name, fx Function) AssignStat { 7 // TODO: include the "function" keywork in the location calculation 8 if method.Val != "" { 9 loc := fx.Locate() 10 fx = NewFunction( 11 nil, nil, 12 ParList{append([]Name{{Val: "self"}}, fx.Params...), fx.HasDots}, 13 fx.Body, 14 ) 15 fx.Location = loc 16 fx.Name = method.FunctionName() 17 fName = NewIndexExp(fName, method.AstString()) 18 } else { 19 fx.Name = fName.FunctionName() 20 } 21 return NewAssignStat([]Var{fName}, []ExpNode{fx}) 22 }