Skip to content

can not use State.Next() func read lua array #102

Description

@Fruneng
       // balabala....

	if l.IsTable(-1) {
		var m = map[string]string{}

		l.PushNil()
		for l.Next(-2) {
			key, _ := l.ToString(-2)
			value, _ := l.ToString(-1)
			l.Pop(1)

			m[key] = value
		}

		l.Pop(2)

		return m
	}

        // balabala....

table is ok, but array will panic.

add some debug log tables.go:215

func arrayIndex(k value) int {
        if n, ok := k.(float64); ok {
           fmt.Println("array_index", k, n)
        } else {
           t := reflect.TypeOf(k)
	   fmt.Println("array_index", t, k)
        }

	if n, ok := k.(float64); ok {
		if i := int(n); float64(i) == n {
			return i
		}
	}
	return -1
}

it is a string type.

array_index <nil> <nil>
array_index string 1
array_index string 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions