General questions

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

General questions

steventidwell
Hi. This is my first post to the mailing list and I have a few questions. I have used some Lua before in WoW modding and am now working on a game in c++. What I would like to know is if anyone has any good explanations of how to set up event triggers using Lua. For example setting timers and checking for events sent to a c++ app from a Lua object. Any help would be greatly appreciated. Thanks!

Reply | Threaded
Open this post in threaded view
|

Re: General questions

Javier Guerra Giraldez
[hidden email] wrote:
> Hi. This is my first post to the mailing list and I have a few questions. I have used some Lua before in WoW modding and am now working on a game in c++. What I would like to know is if anyone has any good explanations of how to set up event triggers using Lua. For example setting timers and checking for events sent to a c++ app from a Lua object. Any help would be greatly appreciated. Thanks!

these are WoW-specific issues, not really Lua language related.

here we generally talk about the Lua language; but it's common to mention some specific applications or libraries.  curiously, WoW isn't a common theme, even if it's the most widely known Lua environment!

so, i think you'd have more luck on a WoW-specific list or forum.  of course, if somebody else here knows WoW enough to give you some pointers, nobody will object.


--
Javier
Reply | Threaded
Open this post in threaded view
|

Re: General questions

steve donovan
On Mon, Jun 1, 2009 at 9:37 AM, Javier Guerra <[hidden email]> wrote:
> [hidden email] wrote:
>> Hi. This is my first post to the mailing list and I have a few questions. I have used some Lua before in WoW modding and am now working on a game in c++. What I would like to know is if anyone has any good explanations of how to set up event triggers using Lua. For example setting timers and checking for events sent to a c++ app from a Lua object. Any help would be greatly appreciated. Thanks!
>
> these are WoW-specific issues, not really Lua language related.

I think the OP is specifically talking about doing a new game, not a
WoW extension, so this is a relevant question.

The first question would be: what platform?

steve d.
Reply | Threaded
Open this post in threaded view
|

Re: General questions

Javier Guerra Giraldez
In reply to this post by Javier Guerra Giraldez
Javier Guerra wrote:
> [hidden email] wrote:
> > Hi. This is my first post to the mailing list and I have a few questions. I have used some Lua before in WoW modding and am now working on a game in c++. What I would like to know is if anyone has any good explanations of how to set up event triggers using Lua. For example setting timers and checking for events sent to a c++ app from a Lua object. Any help would be greatly appreciated. Thanks!
>
> these are WoW-specific issues, not really Lua language related.

...and of course, as soon as i hit 'send', i realize you're not asking about WoW; but you're developing your own game.

welcome, then! this is some of the things we do like to discuss here :-)

in general, you have to design some API to expose the functionality of your core to Lua.  there are several styles for this, and you can create your own.

specifically, for events and timers, two main ways are:

1) installing callbacks

2) using coroutines

this can be a long and interesting discussion.  also check the list archives, you might get some ideas already discussed and criticized.

--
Javier
Reply | Threaded
Open this post in threaded view
|

Re: General questions

Doug Rogers
In reply to this post by steventidwell
[hidden email] wrote:
> .. What I would like to know is if anyone has any good explanations
> of how to set up event triggers using Lua. ...

You might want to take a look at the Game Programming section of Lua
Programming Gems, particularly chapters 21 "A Dynamic and Flexible Event
System for Script-Driven Games" and 23 "Designing an Efficient Lua
Driven Game Scripting Engine".

http://www.lua.org/gems/

I do not have my copy of the book with me so I cannot say whether or not
they address your needs exactly, but you're sure to find many things of
interest in the book.

Since you're familiar with the WoW API (I am not), then perhaps you
could model yours after that. As noted earlier, it is the most used Lua
embedding in the universe (to date).

Also, there are many different projects publicly available. Check out
the Lua forge and the wiki, particularly:

http://luaforge.net/
http://lua-users.org/wiki/LuaAddons
http://lua-users.org/wiki/BindingCodeToLua

Lastly, a Google search may turn up open source projects that use Lua
with C++. My first hit was this:

http://stackoverflow.com/questions/558446/which-open-source-programs-are-good-examples-of-integrating-c-and-lua

I saw good commentary in:

http://www.ogre3d.org/forums/viewtopic.php?f=16&t=47805

Good luck!

Doug

______________________________________________________________________________________
The information contained in this email transmission may contain proprietary and business
sensitive information.  If you are not the intended recipient, you are hereby notified that
any review, dissemination, distribution or duplication of this communication is strictly
prohibited.  Unauthorized interception of this e-mail is a violation of law.  If you are not
the intended recipient, please contact the sender by reply email and immediately destroy all
copies of the original message.

Any technical data and/or information provided with or in this email may be subject to U.S.
export controls law.  Export, diversion or disclosure contrary to U.S. law is prohibited.  
Such technical data or information is not to be exported from the U.S. or given to any foreign
person in the U.S. without prior written authorization of Elbit Systems of America and the
appropriate U.S. Government agency.
Reply | Threaded
Open this post in threaded view
|

Re: General questions

Asko Kauppi
In reply to this post by steventidwell

You might try Lanes or some other multithreading approach.  These will  
allow you to have the event polling loop run as a separate thread, and  
pass things on to worker threads from there.

Otherwise, you'll need to create an event handler and event queue in  
the C side and read it from Lua.

-asko


[hidden email] kirjoitti 1.6.2009 kello 10:20:

> Hi. This is my first post to the mailing list and I have a few  
> questions. I have used some Lua before in WoW modding and am now  
> working on a game in c++. What I would like to know is if anyone has  
> any good explanations of how to set up event triggers using Lua. For  
> example setting timers and checking for events sent to a c++ app  
> from a Lua object. Any help would be greatly appreciated. Thanks!
>

Reply | Threaded
Open this post in threaded view
|

Re: General questions

Steven Johnson
In reply to this post by Javier Guerra Giraldez
(Apologies if this ends up as something of a double post.)

> in general, you have to design some API to expose the functionality of your core to Lua.  there are several styles for this, and you can create your own.
>
> specifically, for events and timers, two main ways are:
>
> 1) installing callbacks
>
> 2) using coroutines

I whipped up a little example, using callbacks, on top of another demo
I did a short while ago. I've got some coroutine functionality that
would be worthwhile too, but it might take some time to write a useful
example (the Textbox update logic may give some hint of it, though; see
below). Still, one of said callbacks uses a coroutine.

I've always gotten really good results by having a few event streams,
executed at key points, into which you can add events at will. All the
events in these streams get executed, in order, and can choose to stick
around afterward (in this case, by returning true) for next time.

In the linked demo, and in the game code from which it was adapted,
the bulk of the game flow occurs in Lua, which it enters at a few
well-defined points. These entry point functions in turn send messages
to the current section ("section" is, more or less, a poorly chosen name
for a window and its callback). Certain important messages are sandwiched
between event stream executions, e.g.

 -- The "enter_update" stream is executed
 -- The current section processes its update logic
 -- The "leave_update" stream is executed

I hope that made at least some sense; this is a bit difficult to
explain concisely. :P
It might be more evident in the code, which you can find in the
"Scripts" folder.
In particular see these:

Base/CoroutineOps.lua

-- Some useful control flow operations.

Class/Control/Stream.lua

-- The stream object itself.

Class/UI/Widget/Textbox.lua

-- Possibly interesting (relevant?) use of coroutine.

Game/Game.lua

-- At the top are the F1, F2, F3 events.
-- The entry points, which could be exposed to C++ and lua_pcall()'d
into. (Never mind WithBoundGroups. It just wraps some context around
the function for split-screen awareness.)

Section/Main.lua

-- An example section, which also throws together the GUI.

Support/Section.lua

-- The stock section implementation, with the event streams.

Support/Tasks.lua

-- These are a bunch of pre-built tasks or task primitives, including
some of those I use here.

Support/Transitions.lua

-- Some more task stuff, mostly for GUIs, though unfortunately I
haven't added an example.

Support/Windows.lua

-- Some of the code behind the section and GUI stuff.

Anyhow, you can find the demo here:

http://blog.xibalbastudios.com/?p=50

and run it with this program:

http://love2d.org/download

The .love is just a renamed zip file, so switch it back to .zip to inspect
the code. If you're on Windows, the batch file in the zip can generate
some documentation (see post), though almost all relevant material is
in the half I have yet to write. :(

In the demo itself, you can press F1, F2, or F3 to set a one-time
timer; set a periodic, permanent timer; or run an asynchonous event,
respectively. A bunch of stuff will print out on the left side.
Reply | Threaded
Open this post in threaded view
|

Re: General questions

Ruzsa Balazs
In reply to this post by steventidwell
At Mon, 1 Jun 2009 07:20:38 +0000,
[hidden email] wrote:
>
> Hi. This is my first post to the mailing list and I have a few
> questions. I have used some Lua before in WoW modding and am now
> working on a game in c++. What I would like to know is if anyone has
> any good explanations of how to set up event triggers using Lua. For
> example setting timers and checking for events sent to a c++ app from
> a Lua object. Any help would be greatly appreciated. Thanks!

Hello,

if you are on Windows, and you have the time, have a look at this:

http://rb.omkamra.hu/moonshine-20090602.tar.gz

I put this together when I was learning Lua.

May give you ideas on how to implement the following stuff:

- binding C libraries to Lua (OpenGL + libjpeg + Windows MIDI output device)
- event system (binding Win32 keyboard/mouse events to Lua handlers)
- coroutine scheduler

As of timers, you may be interested in understanding how calls like
Timer.wait(1000, Timer.MS) don't block the scheduler from running other
Lua threads while the blocking call returns.

Dependencies:

- MinGW
- Lua 5.1
- GLEW
- libjpeg
- freetype2

(FT2 is not really needed, just uncomment the Font module in the
Makefile, it's currently not used by anything)

Happy hacking,
rb
Reply | Threaded
Open this post in threaded view
|

Re: Re: General questions

李慧霸
In reply to this post by Javier Guerra Giraldez
>...and of course, as soon as i hit 'send', i realize you're not asking about WoW; but you're
>developing your own game.
 
>welcome, then! this is some of the things we do like to discuss here :-)

Why isn't WoW welcomed here? A curious phenomenon.


Reply | Threaded
Open this post in threaded view
|

Re: Re: General questions

Javier Guerra Giraldez
2009/6/2 李慧霸 <[hidden email]>:
>>...and of course, as soon as i hit 'send', i realize you're not asking about WoW; but you're
>>developing your own game.
>
>>welcome, then! this is some of the things we do like to discuss here :-)
>
> Why isn't WoW welcomed here? A curious phenomenon.

it _is_ welcomed!  my answer was because if the questions were
WoW-specific (and not about the Lua language), then he would get much
better advice on a WoW-forum (there are lots) than here


--
Javier
Reply | Threaded
Open this post in threaded view
|

Re: General questions

Doug Rogers
In reply to this post by 李慧霸
李慧霸 wrote:
> Why isn't WoW welcomed here? A curious phenomenon.

WoW users/modders are certainly welcome here, but I think most of them
have no real interest in the development of the language itself (though
we do often get posts from beginners). I suspect that WoW modders are
more interested in the WoW API. They'll get better responses at a forum
dedicated to that purpose, and in fact would probably not even see this
list until they've gotten further along in modding WoW.

In other words, they are welcome to post Lua language questions, but in
practice they seldom do.

Doug


______________________________________________________________________________________
The information contained in this email transmission may contain proprietary and business
sensitive information.  If you are not the intended recipient, you are hereby notified that
any review, dissemination, distribution or duplication of this communication is strictly
prohibited.  Unauthorized interception of this e-mail is a violation of law.  If you are not
the intended recipient, please contact the sender by reply email and immediately destroy all
copies of the original message.

Any technical data and/or information provided with or in this email may be subject to U.S.
export controls law.  Export, diversion or disclosure contrary to U.S. law is prohibited.  
Such technical data or information is not to be exported from the U.S. or given to any foreign
person in the U.S. without prior written authorization of Elbit Systems of America and the
appropriate U.S. Government agency.