lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

The question is, are you making a "pure" functional language or an
easy-to-use scripting language with functional ability?

>From what I've read about lua it is the latter.  There are dozens of other
pure functional languages out there for people to experiment with, however
lua hits a niche with its small lightweight structure and easy-to-plugin
functionality and easy-to-read syntax.

Also, on a completely different note; whilst I would *never ever* use gotos
in C++ or even C for that matter, there is an argument for having them in a
*multi-threaded* scripting language. (note the emphasis on multi-threaded)

With multi-threaded scripting languages, especially those for games, it is
necessary to implement state machines, or more simply put, areas of code you
can *jump* to, to get a character to go into a particular state.

I understand why lua doesn't have this right now, the "co-routines" are a
far call from multi-threading and require the user to write a whole
multi-threading kernel in order to use them.  However, once this is written
you begin wanting to write code like this:  (believe me, you really *do*)
(pseudo code)

Thread AlienMonster
    initialise_state()        // initialise function for this monster

    nearest_player = check_for_nearest_player();
    if ( nearest_player )
        jump_to_state( attack );

    play( "scratch_arse" );        // animation (takes time to complete)
    wait( 5 )
    play( "look_around_aimlessly" );
    jump_to_state( check );

    play( "monster_roar" );
    while ( nearest_player == check_for_nearest_player() )
        if ( turn_to_player() )        // facing player?
            play( "chase_1_step" );        // step towards the player (takes
time for animation to complete)
        wait( 1 )     // wait 1 frame (or nth of a second)
    jump_to_state( check );

Of course I can make "attack", "idle" and "check" functions and then have
some kind of table which is run through in order, but then there are no
*conditions*, and quite frankly, setting up the table is just as much a pain
in the arse as writing the above using while/dos and lots of local "state"
variables, which is definitely *not* the way to write that kind of code.
Importantly, the above is *simple to understand*.

Just some thoughts for the stewpot, (based on 15 years experience writing
and using script languages for games)


Q-Games, Dylan Cuthbert.

----- Original Message ----- 
From: "Tuomo Valkonen" <>
Newsgroups: gmane.comp.lang.lua.general
Sent: Monday, June 23, 2003 10:27 PM
Subject: Re: Re[2]: why no "continue" statement for loops?

> On Mon, Jun 23, 2003 at 07:35:24PM +0900, Dylan Cuthbert wrote:
> > I second this break <n> continue <n>  syntax.
> > So please, someone put it in the main lua source so I don't have to keep
> > patching it.
> While I don't miss continue, I'm not opposed to adding it. I am, however,
> _strongly_ opposed to complicating the language with break and continue
> levels. If you add those, you might just as well add 'goto' and we all
> know how people feel about it. (I actually use goto in C, but only to
> jump to an error handler at the end of a function. In languages like
> Lua 1) most of the time there is no need for such handlers and 2) when
> there is, there are many alternative implementations thanks to lexical
> scoping and first-class functions.)
> -- 
> Tuomo