lua_State * pointers

Started by
5 comments, last by meeshoo 20 years, 11 months ago
Hi.I''ve managed to create an engine wich unify all it''s parts through a console wich is using lua to manage the rest.I have some lua threads(lua_State * pointers) in each of the engine parts(renderer, input system, etc) in wich i execute specific commands.my problem is:i want to switch through this pointers so one of it and only one should be active at a given time.so let''s say i have: lua_State * x1; lua_State * x2;//both of them are initialized and are running //command whenever i want //and i have lua_State * current = NULL; What I want is to do operations like current = x1; or current = x2; and to run the commands in the current thread.so the idea is so i can switch between the states.the build of the project runs ok but the problem appears on execution where i get an error: adress "an address in hexa of the specified thread" cannot be "read".so why''s that and how can i assign to my "current" pointer one of the other pointers.Normally it should work cause they have the same type, but it doesn''t.. please help Mihai
Advertisement
Have you assigned each pointer with the result of a UNIQUE call to lua_open()?

Also, why are you doing this? it sounds like multiple lua states are quite possibly not what you want here... separate global tables or coroutines might be more up your alley.

How appropriate. You fight like a cow.
yes, i have each thread is created separately.anyway, i''m pretty newbie to Lua, so what i''ve done till now(what i''ve described before and a little version of opengl) for me is much.i think that i wanned multithreading, because i want that threads to run one in paralel with each other, wich i don''t think i can do with the soultion u gave me.

well, what about my problem? the threads are working independently, there is no doubt.the only error appears when i am trying to assign to a pointer the value of another pointer. Another fact(wich i forgot to mention) is that the pointer named above current is null and is not initialized with lua_open. is this the problem?

Mihai
When you run it in the debugger, what line exactly does the error occur on? It seems very unlikely that an assignment to a local would cause an error like that, unless the stack pointer was corrupted.

How appropriate. You fight like a cow.
depends of what thread i want to assign to the current thread.so if i want to assign the first one created, in the debugger it''s says somthing about afxwindowproc..bla...bla(the dialog window creation) and then it writes 00...000() and and that''s all(it''s an error in disassembley and i don''t know it, only C).and when i start debugging it says something about acces violation at 0000...005.if i try to assign another thread, there is another address but the same error.it''s pretty strange.

Mihai
right, right. But going down through the stack trace, which of your functions is causing the error, and on what line?

If you don''t really know how to use the msvc debugger, this is a good time to learn.

How appropriate. You fight like a cow.
well, it looks like i''ve missunderstood the problem.it gives the error if i''m trying to do any assignment,not that specific one(even int i = 1.so i''ll try to put it somewhere else.anyway, thanks very much for your atention.i''ll post any problem if i''ll have some more.

thanks again

Mihai

This topic is closed to new replies.

Advertisement