zenliucn / glu Goto Github PK
View Code? Open in Web Editor NEWextension for gopher-lua
License: MIT License
extension for gopher-lua
License: MIT License
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......
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.