Lua and c++ co-routines

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
sk1v3r
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 25
Joined: Sun Jan 09, 2011 1:36 pm

Lua and c++ co-routines

Post by sk1v3r »

This is at the moment a theoretical for me, but I remember in an AiGD Falco said something about having a continuous script running through the game with its only infinite loop. My question is, was this achieved with co-routines or is there a need for a sneaky alternative :)
User avatar
M_D_K
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1087
Joined: Tue Oct 28, 2008 10:33 am
Favorite Gaming Platforms: PC
Programming Language of Choice: C/++
Location: UK

Re: Lua and c++ co-routines

Post by M_D_K »

it was done with co-routines. At the end of every iteration in the loop (in the script) it calls a yield function which returns control back to the C++ side of things.
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Lua and c++ co-routines

Post by Falco Girgis »

M_D_K wrote:it was done with co-routines. At the end of every iteration in the loop (in the script) it calls a yield function which returns control back to the C++ side of things.
^ HOW DO YOU KNOW THIS!?

owait... :)

I don't recommend that approach, though. That stuff was way back when I was first learning Lua. Simply load a script with luaL_dofile() and manually invoke an update() function within the script from your C/++ main loop (as you would any normal function). There's no need to use coroutines.
sk1v3r
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 25
Joined: Sun Jan 09, 2011 1:36 pm

Re: Lua and c++ co-routines

Post by sk1v3r »

that's cool :) But doesn't that mean no globals for scripts? or is that a good thing as its more OO?
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Lua and c++ co-routines

Post by Falco Girgis »

sk1v3r wrote:that's cool :) But doesn't that mean no globals for scripts? or is that a good thing as its more OO?
Nope. Any variable you declare without explicitly using the "local" keyword is global. And any global logic (outside of a function) executes once upon loading of the script (for initialization/consruction, etc).
sk1v3r
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 25
Joined: Sun Jan 09, 2011 1:36 pm

Re: Lua and c++ co-routines

Post by sk1v3r »

I meant like persisting globals between scripts, or is that what you were saying ?
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Lua and c++ co-routines

Post by Falco Girgis »

sk1v3r wrote:I meant like persisting globals between scripts, or is that what you were saying ?
It was a matter of "persisting globals between INVOKATION of a single script" that was the issue addressed by that Adventures in Game Development video. To share globals between actual scripts (lua_States), you'd have to push and pop them into each other...
sk1v3r
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 25
Joined: Sun Jan 09, 2011 1:36 pm

Re: Lua and c++ co-routines

Post by sk1v3r »

okay, thanks :)
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Lua and c++ co-routines

Post by dandymcgee »

GyroVorbis wrote:
sk1v3r wrote:I meant like persisting globals between scripts, or is that what you were saying ?
It was a matter of "persisting globals between INVOKATION of a single script" that was the issue addressed by that Adventures in Game Development video. To share globals between actual scripts (lua_States), you'd have to push and pop them into each other...
Invokation Edukation?
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Lua and c++ co-routines

Post by Falco Girgis »

dandymcgee wrote:
GyroVorbis wrote:
sk1v3r wrote:I meant like persisting globals between scripts, or is that what you were saying ?
It was a matter of "persisting globals between INVOKATION of a single script" that was the issue addressed by that Adventures in Game Development video. To share globals between actual scripts (lua_States), you'd have to push and pop them into each other...
Invokation Edukation?
Already planned. That's nothing. We planned to show our entire implementation, which is 1000x deeper than our old, shitty "heartbeat" implementation previously.
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: Lua and c++ co-routines

Post by N64vSNES »

GyroVorbis wrote:
dandymcgee wrote:
GyroVorbis wrote:
sk1v3r wrote:I meant like persisting globals between scripts, or is that what you were saying ?
It was a matter of "persisting globals between INVOKATION of a single script" that was the issue addressed by that Adventures in Game Development video. To share globals between actual scripts (lua_States), you'd have to push and pop them into each other...
Invokation Edukation?
Already planned. That's nothing. We planned to show our entire implementation, which is 1000x deeper than our old, shitty "heartbeat" implementation previously.
I'm all ways 1 step behind :|
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: Lua and c++ co-routines

Post by eatcomics »

N64vSNES wrote:
GyroVorbis wrote:
dandymcgee wrote:
GyroVorbis wrote:
sk1v3r wrote:I meant like persisting globals between scripts, or is that what you were saying ?
It was a matter of "persisting globals between INVOKATION of a single script" that was the issue addressed by that Adventures in Game Development video. To share globals between actual scripts (lua_States), you'd have to push and pop them into each other...
Invokation Edukation?
Already planned. That's nothing. We planned to show our entire implementation, which is 1000x deeper than our old, shitty "heartbeat" implementation previously.
I'm all ways 1 step behind :|
No ES is just one step ahead... maybe you should try researching other things? which reminds me... I have to research ruby as a scripting language....
Image
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Lua and c++ co-routines

Post by dandymcgee »

GyroVorbis wrote:
dandymcgee wrote:
GyroVorbis wrote:
sk1v3r wrote:I meant like persisting globals between scripts, or is that what you were saying ?
It was a matter of "persisting globals between INVOKATION of a single script" that was the issue addressed by that Adventures in Game Development video. To share globals between actual scripts (lua_States), you'd have to push and pop them into each other...
Invokation Edukation?
Already planned. That's nothing. We planned to show our entire implementation, which is 1000x deeper than our old, shitty "heartbeat" implementation previously.
Actually I was just being a smart ass and making fun of the spelling, but that works too. 8-)
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Lua and c++ co-routines

Post by Falco Girgis »

eatcomics wrote:
N64vSNES wrote:
GyroVorbis wrote:
dandymcgee wrote:
GyroVorbis wrote:
sk1v3r wrote:I meant like persisting globals between scripts, or is that what you were saying ?
It was a matter of "persisting globals between INVOKATION of a single script" that was the issue addressed by that Adventures in Game Development video. To share globals between actual scripts (lua_States), you'd have to push and pop them into each other...
Invokation Edukation?
Already planned. That's nothing. We planned to show our entire implementation, which is 1000x deeper than our old, shitty "heartbeat" implementation previously.
I'm all ways 1 step behind :|
No ES is just one step ahead... maybe you should try researching other things? which reminds me... I have to research ruby as a scripting language....
Don't bother. Unless you wish to embed one of the heaviest-weight, slowest scripting languages around.

Ruby is great, but it is NOT great as an embedded, real-time scripting language.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: Lua and c++ co-routines

Post by eatcomics »

Ah, I see. I always liked Ruby... So I figured I might look into using it with my engine, but I believe the words you are speaking.
Image
Post Reply