Giter Site home page Giter Site logo

glu's People

Contributors

zenliucn avatar

Watchers

 avatar  avatar

glu's Issues

`SetGlobal` is not working after lua vm is recycled

I am trying to use glu to recycle lua vm and using GetGlobal / SetGlobal to access lua global variants in Go. Howerver, some counterintuitive behavior were found.

Considering this unit test:

func TestGlu(t *testing.T) {
	vmPool := glu.CreatePool()
	vm := vmPool.Get()
	assert.NotNil(t, vm)
	vmaddr := fmt.Sprintf("%p", vm)

	assert.Equal(t, lua.LNil, vm.GetGlobal("__SOME_KEY__"))       // Passed
	assert.NoError(t, vm.DoString("assert(__SOME_KEY__ == nil)")) // Passed, __SOME_KEY__ is nil in and out of lua
	vm.SetGlobal("__SOME_KEY__", lua.LString("ZZZZZZ"))
	assert.Equal(t, lua.LString("ZZZZZZ"), vm.GetGlobal("__SOME_KEY__")) // Passed
	assert.NoError(t, vm.DoString("assert(__SOME_KEY__ == 'ZZZZZZ')"))   // Passed, __SOME_KEY__ is same in and out of lua

	vmPool.Put(vm) // Recycle the vm
	vm = vmPool.Get()
	vmaddr2 := fmt.Sprintf("%p", vm)
	assert.Equal(t, vmaddr, vmaddr2) // vm is actually recycled

	// Something strange happened....
	// Global is not reset after recycle
	assert.Equal(t, lua.LNil, vm.GetGlobal("__SOME_KEY__")) // Assertion failed, Value still exists out of lua
	// But I cannot find it in lua, __SOME_KEY__ is nil
	assert.NoError(t, vm.DoString("assert(__SOME_KEY__ == nil)")) // Passed, Nothing in lua

	// What if I set it again?
	vm.SetGlobal("__SOME_KEY__", lua.LString("YYYYYY"))
	assert.Equal(t, lua.LString("YYYYYY"), vm.GetGlobal("__SOME_KEY__")) // Passed
	assert.NoError(t, vm.DoString("assert(__SOME_KEY__ == nil)"))        // Passed, SetGlobal is not working
}

When a lua vm has been recycled(in vmPool.Put(vm)), *LState shoule be considered as reseted as what I got this vm at the first time, but GetGlobal is still returning the previous value. Moreover, if I tried to use SetGlobal again, the value would not be set in lua like previous.

I have no idea about what was happening......

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.