diff --git a/config.go b/config.go index 6d424b0..c611921 100644 --- a/config.go +++ b/config.go @@ -20,27 +20,27 @@ type Configuration struct { } // getStringFromTable retrieves a string from a table on the lua stack using the key passed in. +// +// If the value is nil, 'out' is unchanged. func getStringFromTable(L *lua.LState, lobj lua.LValue, key string, out *string) (bool, error) { lv := L.GetTable(lobj, lua.LString(key)) if text, ok := lv.(lua.LString); ok { // Value is string *out = string(text) } else if _, ok := lv.(*lua.LNilType); !ok { // Value is not a string, and is not nil return true, errors.New("'" + key + "' is not a string") - } else { // Value is nil - return false, errors.New("'" + key + "' is nil") } return true, nil } // getIntFromTable retrieves an integer from a table on the Lua stack using the key passed in. +// +// If the value is nil, 'out' is unchanged. func getIntFromTable(L *lua.LState, lobj lua.LValue, key string, out *int64) (bool, error) { lv := L.GetTable(lobj, lua.LString(key)) if int, ok := lv.(lua.LNumber); ok { // Value is number *out = int64(int) } else if _, ok := lv.(*lua.LNilType); !ok { // Value is not a number, and is not nil return true, errors.New("'" + key + "' is not a number") - } else { // Value is nil - return false, errors.New("'" + key + "' is nil") } return true, nil }