|
|
在Lua的文档中关于Threads有这么一段描述:
The following function creates a new thread in Lua:
lua_State *lua_newthread (lua_State *L);
This function pushes the thread on the stack and returns a pointer to a lua_State that represents this new thread. The new state returned by this function shares with the original state all global objects (such as tables), but has an independent run-time stack.
Each thread has an independent global environment table. When you create a thread, this table is the same as that of the given state, but you can change each one independently.
最开始看到这段话时我们认为有冲突,第一段说所有的state共享全局对象(写了测试程序,对于lua_set/gettable的LUA_GLOBALSINDEX,所有的state,无论是original state的还是用lua_newthread创建的new thread都是共享的)。但是后一段说每个线程都有一个独立的全局环境表,那么我想这个全局环境表和全局对象应该是分开的,但是我不知道如何去操作(set/get)这个全局环境表(global environment table),那么,我想对它进行操作,应该如何做呢?谢谢~~~ |
|