Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

smokes

Using LUA for scripting

This topic is 5660 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Isn't anyone here using LUA for scripting? just discovered it the other day and I think it is really nice for embedding into an engine.. [edited by - Smokes on November 20, 2002 10:56:53 AM]

Share this post


Link to post
Share on other sites
Advertisement
We discovered LUA recently and after looking at several other languages decided to use it.

Pro:

a) simple to include
b) small in size and simple, yet powerful (Python anyone?)
c) can be used to interact with C/C++ easily (look at LUA++, or LUNA helper class)

Con:

a) I have yet to find a way to use LUA for timed scripting (something like movie sequences, e.g.
moveleft( 2 ); wait( 200 ); moveright( 2 ); )

Also i know that a some commercial games used LUA for their scripting, a list is available at lua.org.

Regards,

Endurion


Share this post


Link to post
Share on other sites
Endurion: I have the same problem.. But in version 5 which is still in alpha they have implemented minithreads and a yield/resume feature.. if you call yield() inside the script the parser will return in your host program with a code indicating that is is yielding.. then when you''ve done some work you can resume the script.. guess this is what we are looking for.. but it is still not documented.. Also some dude made patch for LUA 4 with a yield/resume function

Share this post


Link to post
Share on other sites
Endurion, you could probably write a scripted function the likes of:


move (time)
(
if (time = 0) moveleft (2)
else if (time < 200) wait
else if (time = 200) moveright (2)
)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Endurion: for "wait" functionality you can implement simple c function that sleeps the thread, it''s just so simple!!

Share this post


Link to post
Share on other sites
AP: yes if you only want to run one script at a time and you run it in a seperate thread from the gameloop.. And you wouldn''t just wanna Sleep().. you would probably want to wait for some event object :-).. But as I mentioned the functionality is in LUA 5 and in a third party add-on

Share this post


Link to post
Share on other sites
AP: yes, would work, if i would only want one script running in a seperate thread, but alas, i''m thinking of having several scripts running, and this yield/resume stuff sounds just like the thing!

I already downloaded the alpha 5 of LUA, but didn''t look in the code, just the docs, and there''s no yield/resume yet. Let''s hope they make it a part.

Actually i was almost starting to implement something like this myself.

Thanks for all the replies, but actually i wasn''t the one starting the thread

Regards,

Endurion

Share this post


Link to post
Share on other sites
My Lua coroutine system (which I am reeeally proud of) handles this nicely. Event handlers execute simultaneously and can block on arbitrary expressions. For instance:


-- walk 50 pixels, wait 200 frames, then walk 50 pixels again
walk(50)
for i=1, 50 do
yield()
end
walk(50)

-- tell Fred to pick up the sock, wait for him to finish, then cough

callevent(fred, {verb="get", object="sock"})
while ~ fred.action.complete do
yield()
end
cough()


This is all with Lua 5.0 alpha''s coroutine support. 5.0 beta is coming out soon, with certain fundamental changes to coroutines, so if you''re planning something like this it might be a good idea to wait.


Don''t listen to me. I''ve had too much coffee.

Share this post


Link to post
Share on other sites
Sneftel: yes that is a nice function.. But I kindda need some documentation about.. In the lua header I saw that the lua_resume() function took TWO lua_States as arguments.. why two?!?.. I mean you run your script.. then it yields.. then your program call resumes.. all happening in the same lua_State.. what is the need for the second?

gip: well you can download a script for book on lua.. in postscript format (download ghostscript and gview of you are using windows).. and there was also something in portuguese (lucky you, to me it is just nonsense :-).. you can get both from the lua main site http://www.lua.org

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!