Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Fruneng opened this issue Sep 19, 2019 · 0 comments
Open

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

Fruneng opened this issue Sep 19, 2019 · 0 comments

Comments

@Fruneng
Copy link

Fruneng commented Sep 19, 2019

       // 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant