Archived

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

quasty

Questions about lua and luabind

Recommended Posts

Hi, I'm using lua/luabind and the C_API in my gameproject for basic scripting. There are a few things pretty unclear and I was hoping someone could help me with. luabind: do I really have to ship the entire Boost headers with the source code - is everything really needed (after all 1,700 header)? Isn't there a "enough boost headers for luabind"-package out there? luabind: is it somehow possible to bind an entire class to lua? Most times there are just a few methods which should be available in lua. But then I have some classes with a lot and a lot and a lot of methods. Do I really have to define them manually? lua: is there some way of time measuring control in lua? I couldn't find anything in th ref-manual. I'm looking for something which returns the time in msec since the VM started - or something similar. EDIT: And an other question regarding lua. I've begun reading about co-routines in Lua. My question is - can I run an entire script out of the C_API in an seperate Co-routine? So if a scripts checks in a loop - for example if the player has reached a certain point - and then exectues an reaction. But if i ran the script using dofile it blocks the application. Is there a solution for it? The best way would be to create an update for every co-routine once a frame in a secure state of the engine. To make it more secure against inconsistencies. Is it possible with lua? It would be great if someone could help me - thanks!! [edited by - quasty on April 6, 2004 7:33:15 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by quasty
luabind: do I really have to ship the entire Boost headers with the source code - is everything really needed (after all 1,700 header)? Isn''t there a "enough boost headers for luabind"-package out there?

Most likely not. Look in the luabind header for what''s needed.
quote:
luabind: is it somehow possible to bind an entire class to lua? Most times there are just a few methods which should be available in lua. But then I have some classes with a lot and a lot and a lot of methods. Do I really have to define them manually?


C++ has no built-in reflection support, so you will have to manually define each feature.
quote:
lua: is there some way of time measuring control in lua? I couldn''t find anything in th ref-manual. I''m looking for something which returns the time in msec since the VM started - or something similar.

It should be fairly simple to expose some high-res timer function to Lua. Alternatively, there is a lua profiler available, or if you don''t care about the Lua code but rather about the overall performance of the VM, you can use a standard C++ profiler.
quote:
EDIT: And an other question regarding lua. I''ve begun reading about co-routines in Lua. My question is - can I run an entire script out of the C_API in an seperate Co-routine? So if a scripts checks in a loop - for example if the player has reached a certain point - and then exectues an reaction. But if i ran the script using dofile it blocks the application. Is there a solution for it? The best way would be to create an update for every co-routine once a frame in a secure state of the engine. To make it more secure against inconsistencies. Is it possible with lua?

I''m not quite sure what you mean here. Do you want a particular coroutine to be waiting around for some other action to take place, and then continue its execution? If so, yes, that''s possible (with a bit of work).

First off, don''t use dofile. Not because it doesn''t have any legitimate uses, but because most likely you''re not using it for one of them. use loadfile, and then call the returned function. That way, you can use it for whatever you want. Remember that that''s what a script is: one, big function, which may or may not do things like assign other functions to global vairables.

So once you''ve got your function, here''s what you can do: keep a table of all the active coroutines. Each frame, invoke all of them in turn with resume(), and let them run until they yield, removing the ones that are complete. Each thread could do something of nontrivial importance, such as moving someone around, or it could just check whether the player has reached a particular point, and if not, immediately yield.


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites
Thank you for your help.

I''m afraid I havn''t understood the loadfile part.

loadfile is a lua command and not part of the C_API, isn''t it? At least my compiler doesn''t find that command. How should I call these then? At these moment I have certain scripts.lua which I call using dofile in various situations from my C Code.

But have I understood this correctly - I should make every script to a function? I think I can look into the co-routines after I have understood the difference to the lua_dofile way!?

thanks alot

Share this post


Link to post
Share on other sites