Don't trigger warning / error if configuration value is nil.
This makes getStringFromTable() and getIntFromTable() only return errors if there's a type mismatch. Example: 'name' should be a 'string'. If it's a number, an error is triggered.
This commit is contained in:
parent
2e5c3dbed6
commit
c19cb14ade
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user