@@ -29,12 +29,6 @@ func (vt LValueType) String() string {
2929type LValue interface {
3030 String () string
3131 Type () LValueType
32- // to reduce `runtime.assertI2T2` costs, this method should be used instead of the type assertion in heavy paths(typically inside the VM).
33- assertFloat64 () (float64 , bool )
34- // to reduce `runtime.assertI2T2` costs, this method should be used instead of the type assertion in heavy paths(typically inside the VM).
35- assertString () (string , bool )
36- // to reduce `runtime.assertI2T2` costs, this method should be used instead of the type assertion in heavy paths(typically inside the VM).
37- assertFunction () (* LFunction , bool )
3832}
3933
4034// LVIsFalse returns true if a given LValue is a nil or false otherwise false.
@@ -80,11 +74,8 @@ func LVAsNumber(v LValue) LNumber {
8074
8175type LNilType struct {}
8276
83- func (nl * LNilType ) String () string { return "nil" }
84- func (nl * LNilType ) Type () LValueType { return LTNil }
85- func (nl * LNilType ) assertFloat64 () (float64 , bool ) { return 0 , false }
86- func (nl * LNilType ) assertString () (string , bool ) { return "" , false }
87- func (nl * LNilType ) assertFunction () (* LFunction , bool ) { return nil , false }
77+ func (nl * LNilType ) String () string { return "nil" }
78+ func (nl * LNilType ) Type () LValueType { return LTNil }
8879
8980var LNil = LValue (& LNilType {})
9081
@@ -96,21 +87,15 @@ func (bl LBool) String() string {
9687 }
9788 return "false"
9889}
99- func (bl LBool ) Type () LValueType { return LTBool }
100- func (bl LBool ) assertFloat64 () (float64 , bool ) { return 0 , false }
101- func (bl LBool ) assertString () (string , bool ) { return "" , false }
102- func (bl LBool ) assertFunction () (* LFunction , bool ) { return nil , false }
90+ func (bl LBool ) Type () LValueType { return LTBool }
10391
10492var LTrue = LBool (true )
10593var LFalse = LBool (false )
10694
10795type LString string
10896
109- func (st LString ) String () string { return string (st ) }
110- func (st LString ) Type () LValueType { return LTString }
111- func (st LString ) assertFloat64 () (float64 , bool ) { return 0 , false }
112- func (st LString ) assertString () (string , bool ) { return string (st ), true }
113- func (st LString ) assertFunction () (* LFunction , bool ) { return nil , false }
97+ func (st LString ) String () string { return string (st ) }
98+ func (st LString ) Type () LValueType { return LTString }
11499
115100// fmt.Formatter interface
116101func (st LString ) Format (f fmt.State , c rune ) {
@@ -133,10 +118,7 @@ func (nm LNumber) String() string {
133118 return fmt .Sprint (float64 (nm ))
134119}
135120
136- func (nm LNumber ) Type () LValueType { return LTNumber }
137- func (nm LNumber ) assertFloat64 () (float64 , bool ) { return float64 (nm ), true }
138- func (nm LNumber ) assertString () (string , bool ) { return "" , false }
139- func (nm LNumber ) assertFunction () (* LFunction , bool ) { return nil , false }
121+ func (nm LNumber ) Type () LValueType { return LTNumber }
140122
141123// fmt.Formatter interface
142124func (nm LNumber ) Format (f fmt.State , c rune ) {
@@ -168,11 +150,8 @@ type LTable struct {
168150 k2i map [LValue ]int
169151}
170152
171- func (tb * LTable ) String () string { return fmt .Sprintf ("table: %p" , tb ) }
172- func (tb * LTable ) Type () LValueType { return LTTable }
173- func (tb * LTable ) assertFloat64 () (float64 , bool ) { return 0 , false }
174- func (tb * LTable ) assertString () (string , bool ) { return "" , false }
175- func (tb * LTable ) assertFunction () (* LFunction , bool ) { return nil , false }
153+ func (tb * LTable ) String () string { return fmt .Sprintf ("table: %p" , tb ) }
154+ func (tb * LTable ) Type () LValueType { return LTTable }
176155
177156type LFunction struct {
178157 IsG bool
@@ -183,11 +162,8 @@ type LFunction struct {
183162}
184163type LGFunction func (* LState ) int
185164
186- func (fn * LFunction ) String () string { return fmt .Sprintf ("function: %p" , fn ) }
187- func (fn * LFunction ) Type () LValueType { return LTFunction }
188- func (fn * LFunction ) assertFloat64 () (float64 , bool ) { return 0 , false }
189- func (fn * LFunction ) assertString () (string , bool ) { return "" , false }
190- func (fn * LFunction ) assertFunction () (* LFunction , bool ) { return fn , true }
165+ func (fn * LFunction ) String () string { return fmt .Sprintf ("function: %p" , fn ) }
166+ func (fn * LFunction ) Type () LValueType { return LTFunction }
191167
192168type Global struct {
193169 MainThread * LState
@@ -221,28 +197,19 @@ type LState struct {
221197 ctxCancelFn context.CancelFunc
222198}
223199
224- func (ls * LState ) String () string { return fmt .Sprintf ("thread: %p" , ls ) }
225- func (ls * LState ) Type () LValueType { return LTThread }
226- func (ls * LState ) assertFloat64 () (float64 , bool ) { return 0 , false }
227- func (ls * LState ) assertString () (string , bool ) { return "" , false }
228- func (ls * LState ) assertFunction () (* LFunction , bool ) { return nil , false }
200+ func (ls * LState ) String () string { return fmt .Sprintf ("thread: %p" , ls ) }
201+ func (ls * LState ) Type () LValueType { return LTThread }
229202
230203type LUserData struct {
231204 Value interface {}
232205 Env * LTable
233206 Metatable LValue
234207}
235208
236- func (ud * LUserData ) String () string { return fmt .Sprintf ("userdata: %p" , ud ) }
237- func (ud * LUserData ) Type () LValueType { return LTUserData }
238- func (ud * LUserData ) assertFloat64 () (float64 , bool ) { return 0 , false }
239- func (ud * LUserData ) assertString () (string , bool ) { return "" , false }
240- func (ud * LUserData ) assertFunction () (* LFunction , bool ) { return nil , false }
209+ func (ud * LUserData ) String () string { return fmt .Sprintf ("userdata: %p" , ud ) }
210+ func (ud * LUserData ) Type () LValueType { return LTUserData }
241211
242212type LChannel chan LValue
243213
244- func (ch LChannel ) String () string { return fmt .Sprintf ("channel: %p" , ch ) }
245- func (ch LChannel ) Type () LValueType { return LTChannel }
246- func (ch LChannel ) assertFloat64 () (float64 , bool ) { return 0 , false }
247- func (ch LChannel ) assertString () (string , bool ) { return "" , false }
248- func (ch LChannel ) assertFunction () (* LFunction , bool ) { return nil , false }
214+ func (ch LChannel ) String () string { return fmt .Sprintf ("channel: %p" , ch ) }
215+ func (ch LChannel ) Type () LValueType { return LTChannel }
0 commit comments