func (state *State) leave(fr *Frame) *Frame {
	fr.prev.next = fr.next
	fr.next.prev = fr.prev
	fr.next = nil  
	fr.prev = nil  
	fr.state = nil
	state.calls--
	return fr
}
leave leaves the current frame.
package lua
import (
	"fmt"
	"io/ioutil"
	"os"
	"os/exec"
	"path/filepath"
	"strings"
	"github.com/Azure/golua/lua/binary"
	"github.com/Azure/golua/lua/syntax"
)
type runtimeErr error
var version = float64(503)
type ThreadStatus int
const (
	ThreadOK    ThreadStatus = iota  
	ThreadYield                      
	ThreadError                      
)
func (status ThreadStatus) String() string {
	switch status {
	case ThreadOK:
		return "OK"
	case ThreadYield:
		return "YIELD"
	case ThreadError:
		return "ERROR"
	}
	return fmt.Sprintf("unknown thread status %d", status)
}
type thread struct {
	*State
}
func (x *thread) String() string { return "thread" }
func (x *thread) Type() Type     { return ThreadType }
type (
	State struct {
		global *global
		base   Frame  
		calls  int    
	}
	global struct {
		builtins [maxTypeID]*table
		version  *float64
		registry *table
		thread0  *State
		config   *config
		panicFn  Func
	}
)
func NewState(opts ...Option) *State {
	var cfg config
	for _, opt := range opts {
		opt(&cfg)
	}
	state := new(State).reset()
	var (
		registry = newTable(state, 8, 0)
		globals  = newTable(state, 0, 20)
		thread   = &thread{state}
	)
	registry.setInt(MainThreadIndex, thread)
	registry.setInt(GlobalsIndex, globals)
	state.enter(new(Frame))
	state.init(&global{
		registry: registry,
		version:  &version,
		thread0:  state,
		config:   &cfg,
	})
	return state
}
func (ls *State) String() string { return fmt.Sprintf("%p", ls) }
func (state *State) recover(err *error) {
	if r := recover(); r != nil {
		state.Debug(false)
		if e, ok := r.(runtimeErr); ok {
			*err = e
		}
		panic(r)
	}
}
func (ls *State) safely(fn func() error) (err error) {
	defer ls.recover(&err)
	return fn()
}
func (state *State) errorf(format string, args ...interface{}) int {
	return state.panic(runtimeErr(fmt.Errorf(format, args...)))
}
func (state *State) panic(err error) int { panic(err) }
func (state *State) enter(fr *Frame) *Frame {
	state.ensure()
	fp := state.base.prev.next
	state.base.prev.next = fr
	fr.prev = state.base.prev
	fr.next = fp
	fp.prev = fr
	fr.state = state
	fr.depth = state.calls
	state.calls++
	return fr
}