Skip to content

Commit

Permalink
chore: update log message
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed Mar 7, 2024
1 parent 92e7071 commit 82d0e17
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
37 changes: 17 additions & 20 deletions internal/luai/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func arrayInterface(lvalue *lua.LTable) any {
}

func unmarshalWorker(value lua.LValue, reflected reflect.Value) error {
logger.Debugf("reflected: %+v, value type: %s, kind: %s\n", reflected, value.Type(), reflected.Kind())
logger.Debugf("unmarshal: reflected: %+v, value type: %s, kind: %s\n", reflected, value.Type(), reflected.Kind())

switch value.Type() {
case lua.LTTable:
Expand Down Expand Up @@ -250,33 +250,30 @@ func unmarshalWorker(value lua.LValue, reflected reflect.Value) error {
tagMap[tag] = i
}
}
logger.Debugf("reflected: %+v, kind: %s, tagMap: %+v\n", reflected, reflected.Kind(), tagMap)
logger.Debugf("unmarshal: reflected: %+v, kind: %s, tagMap: %+v\n", reflected, reflected.Kind(), tagMap)

(value.(*lua.LTable)).ForEach(func(key, value lua.LValue) {
fieldName := key.String()
logger.Debugf("fieldName: %s, value type: %s\n", fieldName, value.Type())

switch reflected.Kind() {
case reflect.Struct:
field := reflected.FieldByName(fieldName)

// if field is not found, try to find it by tag
if !field.IsValid() {
fieldIndex, ok := tagMap[fieldName]
if !ok {
logger.Debugf("unmarshal: field %s not found in tagMap\n", fieldName)
return
}
field = reflected.Field(fieldIndex)
}
logger.Debugf("unmarshal: fieldName: %s, value type: %s\n", fieldName, value.Type())

field := reflected.FieldByName(fieldName)

if !field.IsValid() {
logger.Debugf("unmarshal: field %s not found in struct\n", fieldName)
// if field is not found, try to find it by tag
if !field.IsValid() {
fieldIndex, ok := tagMap[fieldName]
if !ok {
logger.Debugf("unmarshal: field %s not found in tagMap\n", fieldName)
return
}
field = reflected.Field(fieldIndex)
}

unmarshalWorker(value, field)
if !field.IsValid() {
logger.Debugf("unmarshal: field %s not found in struct\n", fieldName)
return
}

unmarshalWorker(value, field)
})
}
default:
Expand Down
4 changes: 2 additions & 2 deletions internal/luai/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ func Marshal(state *lua.LState, v any) (lua.LValue, error) {
table := state.NewTable()
for i := 0; i < reflected.NumField(); i++ {
field := reflected.Field(i)
fieldType := reflected.Type().Field(i)
if field.Kind() == reflect.Ptr {
field = field.Elem()
}

fieldType := reflected.Type().Field(i)
tag := fieldType.Tag.Get("luai")
if tag == "" {
tag = fieldType.Name
Expand All @@ -49,7 +49,7 @@ func Marshal(state *lua.LState, v any) (lua.LValue, error) {
if err != nil {
return nil, err
}
logger.Debugf("field: %v, tag: %v, sub: %v, kind: %s\n", field, tag, sub, field.Kind())
logger.Debugf("marshal: field: %v, tag: %v, sub: %v, kind: %s\n", field, tag, sub, field.Kind())
table.RawSetString(tag, sub)
}
return table, nil
Expand Down
4 changes: 1 addition & 3 deletions internal/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (l *LuaPlugin) Available() ([]*Package, error) {

for i, addition := range item.Addition {
if addition.Name == "" {
logger.Errorf("additional file %d no name provided", i+1)
logger.Errorf("[Available] additional file %d no name provided", i+1)
}

additionalArr = append(additionalArr, &Info{
Expand Down Expand Up @@ -146,8 +146,6 @@ func (l *LuaPlugin) Checksum(table *lua.LTable) *Checksum {
return NoneChecksum
}

logger.Debugf("checksum: %+v", luaCheckSum)

checksum := &Checksum{}

if luaCheckSum.Sha256 != "" {
Expand Down

0 comments on commit 82d0e17

Please sign in to comment.