From c19cb14ade754b45eefe74ce79ac76c9ce3a9cb3 Mon Sep 17 00:00:00 2001 From: Noah Date: Mon, 15 Apr 2024 15:10:34 -0500 Subject: [PATCH] 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. --- config.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 }