示例#1
0
文件: luaenv.go 项目: hoffoo/luaenv
// Load all edited luas and run them into our state
func (ls luas) Load(L *lua.State) (err error) {

	for path, status := range ls {
		if status == edited {
			err := L.DoFile(path)
			if err != nil {
				fmt.Println("error: ", err)
			}
			ls[path] = lua_loaded
		}
	}

	return nil
}
示例#2
0
// Construct a new LuaConfig given the lua state and file name.
// Returns *LuaConfig, nil on success and nil, error on error.
// Expects that the file provided is a lua script that will return a
// table of strings to values, for example:
// config = {
//   key = "value",
//   boolean = false,
// }
// return config
//
func NewLuaConfig(lua *lua.State, file string) (*LuaConfig, error) {
	lc := &LuaConfig{file: file}

	if err := lua.DoFile(file); err != nil {
		return nil, fmt.Errorf("NewLuaConfig: Can't load %s: %s", file, err)
	} else {
		m := luar.CopyTableToMap(lua, nil, -1)
		lc.conf = m.(map[string]interface{})
	}

	return lc, nil
}