Simple AI Scripting, Help Me!

classic Classic list List threaded Threaded
53 messages Options
123
Tim
Reply | Threaded
Open this post in threaded view
|

Simple AI Scripting, Help Me!

Tim
I have been playing with lua for the last little while trying to get lua working within the game.  I can run a single script via/ lua_dofile, and register some functions.  So I now I have a script such as the following.
 
function playerinit()
local rvalue = 0
    if ( keyhit("DIK_SPACE") > 0 ) then
        drawstring(-1,30,"hit spacebar")
        rvalue = 1
    end
  return rvalue
end
 
ok yeah really simple, I get this just fine, what I want to do is have every player in the game, have it's own script like badguy  uses = badguy.lua, hero uses = hero.lua  what I want to do now is have three states for every player like init, process, exit, so I have a playerinit(), playerproc(), playerexit() in each ai script, so when I process my guy from my c++ code, I can say (from my main process loop c++) registerplayer(this), it registers my luaclass with a pointer to the active player.  Then I  then later call lua .. via lua_getglobal(luaVM, "playerinit") etc, but I want each of my .lua files to have the same function names init proccess exit.  when a state(funcion in lua) is complete it returns true, and then I change from say init to process, and inside process would have commands like..
 
if(enemyisnear()) runforcover();
else patrolpath();
 
That would be my process function, the problem I guess I'm having, is the whole problem with multiple lua_states, and stuff, and how to arrange it, how to set it up, etc.  My app is not multithreaded, but can I use lua_newthread?  I'm basically lost, combing through threads of threads looking for answers so I have come to this.   What it seems as though is happening, is that when I add a new guy into the world, and call lua_dofile(), it basically becomes the script in which all players use, I tried something with calling lua_open and storing a state in the player class, but that didn't seem to work to well..  Ideally I would like to use one lua_state, and then when the lua functions are called from c, it just works itself out, I have no idea, how to set this up.  I'm beyond frustrated, I'm a beginner user, I don't have lots of time to spend researching this stuff, but I want to use it, it's a great language, there must be a good and easy way to do this.  I think I could probably do it if each guy had unique function names, and somehow, store them in the class and call them as needed, but I would rather have the same set of functions for every actor in the world.
 
 
Any Ideas?
 
 
Thanks,
 
Tim Ryness
 
 
Reply | Threaded
Open this post in threaded view
|

RE: Simple AI Scripting, Help Me!

Nick Trout
Sounds like you want to use co-routines. You can fire off several "threads" in a Lua state, each one having a different job. Each one of the co-routines could be a different script/character in your case. See:

http://lua-users.org/wiki/CoroutinesTutorial

You could namespace them and control what they can see using the following example:

http://lua-users.org/lists/lua-l/2003-06/msg00441.html

http://lua-users.org/wiki/MetamethodsTutorial

Nick


-----Original Message-----
From: Tim [[hidden email]] 
Sent: Saturday, December 06, 2003 2:35 PM
To: [hidden email]
Subject: Simple AI Scripting, Help Me!

I have been playing with lua for the last little while trying to get lua working within the game.  I can run a single script via/ lua_dofile, and register some functions.  So I now I have a script such as the following.
 
function playerinit()
local rvalue = 0
    if ( keyhit("DIK_SPACE") > 0 ) then
        drawstring(-1,30,"hit spacebar")
        rvalue = 1
    end
  return rvalue
end
 
ok yeah really simple, I get this just fine, what I want to do is have every player in the game, have it's own script like badguy  uses = badguy.lua, hero uses = hero.lua  what I want to do now is have three states for every player like init, process, exit, so I have a playerinit(), playerproc(), playerexit() in each ai script, so when I process my guy from my c++ code, I can say (from my main process loop c++) registerplayer(this), it registers my luaclass with a pointer to the active player.  Then I  then later call lua .. via lua_getglobal(luaVM, "playerinit") etc, but I want each of my .lua files to have the same function names init proccess exit.  when a state(funcion in lua) is complete it returns true, and then I change from say init to process, and inside process would have commands like..
 
if(enemyisnear()) runforcover();
else patrolpath();
 
That would be my process function, the problem I guess I'm having, is the whole problem with multiple lua_states, and stuff, and how to arrange it, how to set it up, etc.  My app is not multithreaded, but can I use lua_newthread?  I'm basically lost, combing through threads of threads looking for answers so I have come to this.   What it seems as though is happening, is that when I add a new guy into the world, and call lua_dofile(), it basically becomes the script in which all players use, I tried something with calling lua_open and storing a state in the player class, but that didn't seem to work to well..  Ideally I would like to use one lua_state, and then when the lua functions are called from c, it just works itself out, I have no idea, how to set this up.  I'm beyond frustrated, I'm a beginner user, I don't have lots of time to spend researching this stuff, but I want to use it, it's a great language, there must be a good and easy way to do this.  I think I could probably do it if each guy had unique function names, and somehow, store them in the class and call them as needed, but I would rather have the same set of functions for every actor in the world.
 
 
Any Ideas?
 
 
Thanks, 
 
Tim Ryness
 
 

Reply | Threaded
Open this post in threaded view
|

RE: Simple AI Scripting, Help Me!

Kevin Baca-2
In reply to this post by Tim
There are many ways to do this, and the "file == class" technique (where
a file containing methods represents a class) is not necessarily the
easiest or most straightforward.

The most straightforward, IMO, is described here:

http://lua-users.org/wiki/ObjectOrientationTutorial

If you want to use the "file == class" technique, look at loadfile():

http://www.lua.org/manual/5.0/manual.html#5.1

A simple example:

BadGuy.lua
----------
local BadGuy = {}

function BadGuy:doSomething()
    print( "Bad Guy doing something" )
end

return BadGuy

GoodGuy.lua
----------
local GoodGuy = {}

function GoodGuy:doSomething()
    print( "Good Guy doing something" )
end

return GoodGuy

main.lua
--------
local BadGuy = assert( loadfile( "BadGuy.lua" ) )()
local GoodGuy = assert( loadfile( "GoodGuy.lua" ) )()

function createBadGuy()
   return setmetatable( {}, { __index = BadGuy } )
end

function createGoodGuy()
   return setmetatable( {}, { __index = GoodGuy } )
end

Interpreter
-----------
> dofile "main.lua"
> badguy = createBadGuy()
> goodguy = createGoodGuy()
> badguy:doSomething()
Bad Guy doing something
> goodguy:doSomething()
Good Guy doing something
>

See the following for examples on associating lua objects with C
objects:

http://lua-users.org/wiki/SimpleCppBinding

You should try to minimize the number of interfaces between lua and C.
This implies that you should minimize the number of C data structures
that have direct counterparts in lua, and vice versa.

Based on my own experience I've found that if you plan to have most of
your game logic in C, you should create your heavyweight entity
structures in C and use lua only for configuration, variable
definitions, etc.

OTOH, if you plan to have your game logic in lua then your heavyweight
entity structures should be in lua.

-Kevin

-----Original Message-----
From: [hidden email]
[[hidden email]] On Behalf Of Tim
Sent: Saturday, December 06, 2003 2:35 PM
To: [hidden email]
Subject: Simple AI Scripting, Help Me!


I have been playing with lua for the last little while trying to get lua
working within the game.  I can run a single script via/ lua_dofile, and
register some functions.  So I now I have a script such as the
following.

function playerinit()
local rvalue = 0
    if ( keyhit("DIK_SPACE") > 0 ) then
        drawstring(-1,30,"hit spacebar")
        rvalue = 1
    end
  return rvalue
end

ok yeah really simple, I get this just fine, what I want to do is have
every player in the game, have it's own script like badguy  uses =
badguy.lua, hero uses = hero.lua  what I want to do now is have three
states for every player like init, process, exit, so I have a
playerinit(), playerproc(), playerexit() in each ai script, so when I
process my guy from my c++ code, I can say (from my main process loop
c++) registerplayer(this), it registers my luaclass with a pointer to
the active player.  Then I  then later call lua .. via
lua_getglobal(luaVM, "playerinit") etc, but I want each of my .lua files
to have the same function names init proccess exit.  when a
state(funcion in lua) is complete it returns true, and then I change
from say init to process, and inside process would have commands like..

if(enemyisnear()) runforcover();
else patrolpath();

That would be my process function, the problem I guess I'm having, is
the whole problem with multiple lua_states, and stuff, and how to
arrange it, how to set it up, etc.  My app is not multithreaded, but can
I use lua_newthread?  I'm basically lost, combing through threads of
threads looking for answers so I have come to this.   What it seems as
though is happening, is that when I add a new guy into the world, and
call lua_dofile(), it basically becomes the script in which all players
use, I tried something with calling lua_open and storing a state in the
player class, but that didn't seem to work to well..  Ideally I would
like to use one lua_state, and then when the lua functions are called
from c, it just works itself out, I have no idea, how to set this up.
I'm beyond frustrated, I'm a beginner user, I don't have lots of time to
spend researching this stuff, but I want to use it, it's a great
language, there must be a good and easy way to do this.  I think I could
probably do it if each guy had unique function names, and somehow, store
them in the class and call them as needed, but I would rather have the
same set of functions for every actor in the world.


Any Ideas?


Thanks, 

Tim Ryness


Tim
Reply | Threaded
Open this post in threaded view
|

Re: Simple AI Scripting, Help Me!

Tim
Thanks for you help, I really appreciate it, my only question now is I need
to call a function everyframe to update a dudes position or state (every
frame or every 5 or whatever).  Not sure how I would do this with this
example below.  How would it tie in with my player class etc.  I don't want
to really expose a whole players class (from lua), nothing if I can help it.
I want the scripts
to be really high level, so anyone could write scripts for it.  I don't want
to write the scripts myself, I want to set them up, and hand them off to
some else who doesn't have
much knowledge of programming (if need be).  So I don't really want it to
look like c++, or c (lua does resemble it), just they way one would think
enemyclose(), runforcover(), seekhealth(), findescort(), etc etc, and I
expose those functions to lua.  If I load this main.lua it will parse the
whole thing, and stall my app, I call it from my initfunction of my game,
where is before, I called a function to update a guy from c++, everyframe,
and returned true when it finished the function .. his goals.


Thanks,

Tim Ryness

----- Original Message ----- 
From: "Kevin Baca" <[hidden email]>
To: "'Lua list'" <[hidden email]>
Sent: Saturday, December 06, 2003 3:59 PM
Subject: RE: Simple AI Scripting, Help Me!


> There are many ways to do this, and the "file == class" technique (where
> a file containing methods represents a class) is not necessarily the
> easiest or most straightforward.
>
> The most straightforward, IMO, is described here:
>
> http://lua-users.org/wiki/ObjectOrientationTutorial
>
> If you want to use the "file == class" technique, look at loadfile():
>
> http://www.lua.org/manual/5.0/manual.html#5.1
>
> A simple example:
>
> BadGuy.lua
> ----------
> local BadGuy = {}
>
> function BadGuy:doSomething()
>     print( "Bad Guy doing something" )
> end
>
> return BadGuy
>
> GoodGuy.lua
> ----------
> local GoodGuy = {}
>
> function GoodGuy:doSomething()
>     print( "Good Guy doing something" )
> end
>
> return GoodGuy
>
> main.lua
> --------
> local BadGuy = assert( loadfile( "BadGuy.lua" ) )()
> local GoodGuy = assert( loadfile( "GoodGuy.lua" ) )()
>
> function createBadGuy()
>    return setmetatable( {}, { __index = BadGuy } )
> end
>
> function createGoodGuy()
>    return setmetatable( {}, { __index = GoodGuy } )
> end
>
> Interpreter
> -----------
> > dofile "main.lua"
> > badguy = createBadGuy()
> > goodguy = createGoodGuy()
> > badguy:doSomething()
> Bad Guy doing something
> > goodguy:doSomething()
> Good Guy doing something
> >
>
> See the following for examples on associating lua objects with C
> objects:
>
> http://lua-users.org/wiki/SimpleCppBinding
>
> You should try to minimize the number of interfaces between lua and C.
> This implies that you should minimize the number of C data structures
> that have direct counterparts in lua, and vice versa.
>
> Based on my own experience I've found that if you plan to have most of
> your game logic in C, you should create your heavyweight entity
> structures in C and use lua only for configuration, variable
> definitions, etc.
>
> OTOH, if you plan to have your game logic in lua then your heavyweight
> entity structures should be in lua.
>
> -Kevin
>
> -----Original Message-----
> From: [hidden email]
> [[hidden email]] On Behalf Of Tim
> Sent: Saturday, December 06, 2003 2:35 PM
> To: [hidden email]
> Subject: Simple AI Scripting, Help Me!
>
>
> I have been playing with lua for the last little while trying to get lua
> working within the game.  I can run a single script via/ lua_dofile, and
> register some functions.  So I now I have a script such as the
> following.
>
> function playerinit()
> local rvalue = 0
>     if ( keyhit("DIK_SPACE") > 0 ) then
>         drawstring(-1,30,"hit spacebar")
>         rvalue = 1
>     end
>   return rvalue
> end
>
> ok yeah really simple, I get this just fine, what I want to do is have
> every player in the game, have it's own script like badguy  uses =
> badguy.lua, hero uses = hero.lua  what I want to do now is have three
> states for every player like init, process, exit, so I have a
> playerinit(), playerproc(), playerexit() in each ai script, so when I
> process my guy from my c++ code, I can say (from my main process loop
> c++) registerplayer(this), it registers my luaclass with a pointer to
> the active player.  Then I  then later call lua .. via
> lua_getglobal(luaVM, "playerinit") etc, but I want each of my .lua files
> to have the same function names init proccess exit.  when a
> state(funcion in lua) is complete it returns true, and then I change
> from say init to process, and inside process would have commands like..
>
> if(enemyisnear()) runforcover();
> else patrolpath();
>
> That would be my process function, the problem I guess I'm having, is
> the whole problem with multiple lua_states, and stuff, and how to
> arrange it, how to set it up, etc.  My app is not multithreaded, but can
> I use lua_newthread?  I'm basically lost, combing through threads of
> threads looking for answers so I have come to this.   What it seems as
> though is happening, is that when I add a new guy into the world, and
> call lua_dofile(), it basically becomes the script in which all players
> use, I tried something with calling lua_open and storing a state in the
> player class, but that didn't seem to work to well..  Ideally I would
> like to use one lua_state, and then when the lua functions are called
> from c, it just works itself out, I have no idea, how to set this up.
> I'm beyond frustrated, I'm a beginner user, I don't have lots of time to
> spend researching this stuff, but I want to use it, it's a great
> language, there must be a good and easy way to do this.  I think I could
> probably do it if each guy had unique function names, and somehow, store
> them in the class and call them as needed, but I would rather have the
> same set of functions for every actor in the world.
>
>
> Any Ideas?
>
>
> Thanks,
>
> Tim Ryness
>


Reply | Threaded
Open this post in threaded view
|

Using LUA to mimic another language

Christophe Gimenez
Hello, I wonder if LUA is capable to mimic the syntax of another language (more or 
less)... 

So, I could use LUA to prototype another script language.

For example : could LUA partially mimics PASCAL syntax ?? 

Thanks

Reply | Threaded
Open this post in threaded view
|

Re: Using LUA to mimic another language

Adam D. Moss
[hidden email] wrote:
Hello, I wonder if LUA is capable to mimic the syntax of another language (more or less)...
So, I could use LUA to prototype another script language.

For example : could LUA partially mimics PASCAL syntax ??

No.  :)

You could write a (i.e.) pascal parser in lua, of course.  You could
even use that to write a pascal interpreter, or with a lot of effort
to convert pascal source to lua source.  But lua's flexibility
is more in the semantics department than in syntax, so a heavy
preprocessing/parsing stage would almost always be necessary to
have lua even begin to understand another language's syntax 'as
its own' rather than simply hosting an interpreter (at which
lua has no special advantage besides being a neat language in
its own right).

--Adam
--
Adam D. Moss   . ,,^^   [hidden email]   http://www.foxbox.org/   co:3
Consume Less, Live More

Reply | Threaded
Open this post in threaded view
|

RE: Simple AI Scripting, Help Me!

Kevin Baca-2
In reply to this post by Tim
Can you provide a short example script that shows what you want to be
able to?

It doesn't have to be proper lua, just something that shows what you are
trying to achieve.

> Thanks for you help, I really appreciate it, my only question 
> now is I need to call a function everyframe to update a dudes 
> position or state (every frame or every 5 or whatever).  Not 
> sure how I would do this with this example below.  How would 
> it tie in with my player class etc.  I don't want to really 
> expose a whole players class (from lua), nothing if I can 
> help it. I want the scripts to be really high level, so 
> anyone could write scripts for it.  I don't want to write the 
> scripts myself, I want to set them up, and hand them off to 
> some else who doesn't have much knowledge of programming (if 
> need be).  So I don't really want it to look like c++, or c 
> (lua does resemble it), just they way one would think 
> enemyclose(), runforcover(), seekhealth(), findescort(), etc 
> etc, and I expose those functions to lua.  If I load this 
> main.lua it will parse the whole thing, and stall my app, I 
> call it from my initfunction of my game, where is before, I 
> called a function to update a guy from c++, everyframe, and 
> returned true when it finished the function .. his goals.
> 
> 
> Thanks,
> 


Reply | Threaded
Open this post in threaded view
|

Re: Simple AI Scripting, Help Me!

Jared Krinke
In reply to this post by Tim
I'm not sure how helpful this will be, but here goes:

I'm currently using Lua as an embedded scripting language in a game
engine I'm working on. I've exposed the various attributes of the actors
("entities" if you like that term better) via Lua.

My current plan (which is working out nicely) is to expose that
functionality for those that needed and then I write Lua functions to
further wrap up functions when possible (I guess they'd be equivalent to
your "enemyclose," etc., though my game is a top-scrolling shooter).

Additionally, all of the actor attributes (x, y, velocity, acceleration,
angle, etc.) are stored in a C structure (created as a Lua userdata).
This way access from C is still very fast (since the triangle
hit-detection is what currently uses the most CPU time).

Lastly, I've setup my engine so that it automatically loads all Lua
files in a directory. This will allow users to add new weapons and
enemies if they want to give it a shot. Sure they could cheat, but I
want the game to be fun, not hard, so if you wanna cheat, that's just
fine.

I guess I rambled a bit more than necessary. Hopefully some of that was
helpful.

On Sun, 2003-12-07 at 00:46, Tim wrote:
> Thanks for you help, I really appreciate it, my only question now is I need
> to call a function everyframe to update a dudes position or state (every
> frame or every 5 or whatever).  Not sure how I would do this with this
> example below.  How would it tie in with my player class etc.  I don't want
> to really expose a whole players class (from lua), nothing if I can help it.
> I want the scripts
> to be really high level, so anyone could write scripts for it.  I don't want
> to write the scripts myself, I want to set them up, and hand them off to
> some else who doesn't have
> much knowledge of programming (if need be).  So I don't really want it to
> look like c++, or c (lua does resemble it), just they way one would think
> enemyclose(), runforcover(), seekhealth(), findescort(), etc etc, and I
> expose those functions to lua.  If I load this main.lua it will parse the
> whole thing, and stall my app, I call it from my initfunction of my game,
> where is before, I called a function to update a guy from c++, everyframe,
> and returned true when it finished the function .. his goals.
> 
> 
> Thanks,
> 
> Tim Ryness
> 
> ----- Original Message ----- 
> From: "Kevin Baca" <[hidden email]>
> To: "'Lua list'" <[hidden email]>
> Sent: Saturday, December 06, 2003 3:59 PM
> Subject: RE: Simple AI Scripting, Help Me!
> 
> 
> > There are many ways to do this, and the "file == class" technique (where
> > a file containing methods represents a class) is not necessarily the
> > easiest or most straightforward.
> >
> > The most straightforward, IMO, is described here:
> >
> > http://lua-users.org/wiki/ObjectOrientationTutorial
> >
> > If you want to use the "file == class" technique, look at loadfile():
> >
> > http://www.lua.org/manual/5.0/manual.html#5.1
> >
> > A simple example:
> >
> > BadGuy.lua
> > ----------
> > local BadGuy = {}
> >
> > function BadGuy:doSomething()
> >     print( "Bad Guy doing something" )
> > end
> >
> > return BadGuy
> >
> > GoodGuy.lua
> > ----------
> > local GoodGuy = {}
> >
> > function GoodGuy:doSomething()
> >     print( "Good Guy doing something" )
> > end
> >
> > return GoodGuy
> >
> > main.lua
> > --------
> > local BadGuy = assert( loadfile( "BadGuy.lua" ) )()
> > local GoodGuy = assert( loadfile( "GoodGuy.lua" ) )()
> >
> > function createBadGuy()
> >    return setmetatable( {}, { __index = BadGuy } )
> > end
> >
> > function createGoodGuy()
> >    return setmetatable( {}, { __index = GoodGuy } )
> > end
> >
> > Interpreter
> > -----------
> > > dofile "main.lua"
> > > badguy = createBadGuy()
> > > goodguy = createGoodGuy()
> > > badguy:doSomething()
> > Bad Guy doing something
> > > goodguy:doSomething()
> > Good Guy doing something
> > >
> >
> > See the following for examples on associating lua objects with C
> > objects:
> >
> > http://lua-users.org/wiki/SimpleCppBinding
> >
> > You should try to minimize the number of interfaces between lua and C.
> > This implies that you should minimize the number of C data structures
> > that have direct counterparts in lua, and vice versa.
> >
> > Based on my own experience I've found that if you plan to have most of
> > your game logic in C, you should create your heavyweight entity
> > structures in C and use lua only for configuration, variable
> > definitions, etc.
> >
> > OTOH, if you plan to have your game logic in lua then your heavyweight
> > entity structures should be in lua.
> >
> > -Kevin
> >
> > -----Original Message-----
> > From: [hidden email]
> > [[hidden email]] On Behalf Of Tim
> > Sent: Saturday, December 06, 2003 2:35 PM
> > To: [hidden email]
> > Subject: Simple AI Scripting, Help Me!
> >
> >
> > I have been playing with lua for the last little while trying to get lua
> > working within the game.  I can run a single script via/ lua_dofile, and
> > register some functions.  So I now I have a script such as the
> > following.
> >
> > function playerinit()
> > local rvalue = 0
> >     if ( keyhit("DIK_SPACE") > 0 ) then
> >         drawstring(-1,30,"hit spacebar")
> >         rvalue = 1
> >     end
> >   return rvalue
> > end
> >
> > ok yeah really simple, I get this just fine, what I want to do is have
> > every player in the game, have it's own script like badguy  uses =
> > badguy.lua, hero uses = hero.lua  what I want to do now is have three
> > states for every player like init, process, exit, so I have a
> > playerinit(), playerproc(), playerexit() in each ai script, so when I
> > process my guy from my c++ code, I can say (from my main process loop
> > c++) registerplayer(this), it registers my luaclass with a pointer to
> > the active player.  Then I  then later call lua .. via
> > lua_getglobal(luaVM, "playerinit") etc, but I want each of my .lua files
> > to have the same function names init proccess exit.  when a
> > state(funcion in lua) is complete it returns true, and then I change
> > from say init to process, and inside process would have commands like..
> >
> > if(enemyisnear()) runforcover();
> > else patrolpath();
> >
> > That would be my process function, the problem I guess I'm having, is
> > the whole problem with multiple lua_states, and stuff, and how to
> > arrange it, how to set it up, etc.  My app is not multithreaded, but can
> > I use lua_newthread?  I'm basically lost, combing through threads of
> > threads looking for answers so I have come to this.   What it seems as
> > though is happening, is that when I add a new guy into the world, and
> > call lua_dofile(), it basically becomes the script in which all players
> > use, I tried something with calling lua_open and storing a state in the
> > player class, but that didn't seem to work to well..  Ideally I would
> > like to use one lua_state, and then when the lua functions are called
> > from c, it just works itself out, I have no idea, how to set this up.
> > I'm beyond frustrated, I'm a beginner user, I don't have lots of time to
> > spend researching this stuff, but I want to use it, it's a great
> > language, there must be a good and easy way to do this.  I think I could
> > probably do it if each guy had unique function names, and somehow, store
> > them in the class and call them as needed, but I would rather have the
> > same set of functions for every actor in the world.
> >
> >
> > Any Ideas?
> >
> >
> > Thanks,
> >
> > Tim Ryness
> >
> 


Tim
Reply | Threaded
Open this post in threaded view
|

Re: Simple AI Scripting, Help Me!

Tim
In reply to this post by Kevin Baca-2
This is what I have now, it's very early yet, I just started, and I have
bounced things around trying to get this to work, so it's not what I want in
the end, but here it goes.  I have a state machine, that for each state has
an init, proc, exit, and in my init for the main game state, I call the
following.

mylua_Init();

looks like this at this moment ..

static lua_State * ls;

void mylua_Init()
{
     ls  = lua_open();

     if (NULL == ls) logger("Error Initializing Lua\n");
     else
     {
            logger("Lua Initialized\n");

         lua_baselibopen(ls);
      lua_iolibopen(ls);
      lua_strlibopen(ls);
      lua_mathlibopen(ls);

      lua_register( ls, "addNPC", fl_AddNPC );
      lua_register( ls, "drawstring", fl_DrawString );
      lua_register( ls, "drawnumber", fl_DrawNumber );
      lua_register( ls, "getsceneframe", fl_GetSceneFrame );
      lua_register( ls, "findsetlocation", fl_FindSetLocation );
      lua_register( ls, "keyhit", fl_KeyHit);
      lua_register( ls, "setframe", fl_SetSceneFrame);

}

sorry bout the spacing, outlook has hosed my tabs, then I call

mylua_Load("dam.lua");

which looks like this ...

void mylua_Load(const char *scriptname)
{
 pushandsetdir("scripts");
  lua_dofile(ls, scriptname);
 popdir();
}


dam.lua looks like this(looks familor right? :) )

local Hero = assert( loadfile( "hero.lua" ) )()
local GuardGuy = assert( loadfile( "guard01.lua" ) )()

function createHero()
   return setmetatable( {}, { __index = Hero } )
end

function createGuardGuy()
   return setmetatable( {}, { __index = GuardGuy } )
end

Hero = createHero();

Hero:doSomething()



this works fine but it's not what I want, want I had before was I would
create a hero like this

MOBHuman *thisguy;

thisguy = addchar(0,0,0,actorlist);

then I would load a file like ...

 mylua_Load("heroscript.lua");

then in my main loop I would call

void MOBHuman::Processplayer()
{

            which would update the guys position keyboard input , etc etc.

            I would also call something like mylua_aiprocess(this);

            which looked something like this..

            void mylua_aiprocess(MOBHuman *curactor) {

                    int val;

                   // I stored the current actor passed in so that all the
exposed functions of my game knew which was the current guy

                processingactor = curactor;

                 lua_getglobal(ls, "playerprocess");

                 lua_call(ls, 0, 1);

                // so that when it called something from lua like
here is my old scipt I was using

                function playerprocess()
                     local rvalue = 0

                     if ( keyhit("DIK_SPACE") > 0 ) then
                          --drawstring(-1,30,"hit spacebar")
                          setframe(4099,1) -- framenumber, continue playing
                     end

                     if ( findsetlocation("herostart.mxo",1,0) ) then  -- 
lookfor, setposition, setrotation
                          --drawstring(-1,30,"haha found something")
                        else
                          --drawstring(9,30,"ouch didn't find it")
                     end

                     if ( getsceneframe() > 4100 ) then
                          findsetlocation("dockstart.mxo",1,1)
                          rvalue = 1;
                     end

                        return rvalue
                end

                again this loop was called every frame of my game proc, what
this script did was basically take over all input of my game, and force him
to an object

                that moved in the world until frame 4101 or whatever, then
it would bail out, and I would then not call this function any more, this
was sorta a hack to get something

                working, I planned on revising this, and building from it,
when I started having problems with multiple players, having their own
scripts.  the idea here was that when a function was

                called from lua like this ..



                    int fl_FindSetLocation( lua_State * luaVM ){

                                // I could use processingactor in here, and
it would know from(in theory) when it called from lua, that it was dealing
with processingactor

                                // this is also when I starting having
trouble when I added another guy into the world, and created him and loaded
his file, which has the same function name in lua as the hero guy
playerprocess, since

                                  // I guess there was only one lua_State it
was using the latest playerprocess function for all guys

                   }



Hope this isn't too complicated to understand, not even sure the best ways
to do things in lua, I almost wrote my own scripting language, when I
realized I didn't want to

re-invent the wheel (so to speak), and lua I stumbled across, from a company
who didn't make it  and decided to opensource the whole engine, and source,
and binary to

http://catmother.sourceforge.net/  which I applaud them for, and I have
looked that the stuff they have, but it's a wild goose chase trying to
figure out what was going on.

which sometimes is why I hate c++.  Anyways what I what is a highlevel
scipting language with calls that pretty much do all internal stuff within
c++, and I decide

what to do with the results given back from my game.  In order to do this, I
need to be able to have my game call lua basically every frame (maybe every
few) (for characters and other scritables)

to update the status of things.  Of couse with anything you need a
foundation to build from, and my foundation has termites (at the moment)
thats why I look here for help, I appreciate it.

Tim Ryness




---- Original Message ----- 

From: "Kevin Baca" <[hidden email]>
To: "'Lua list'" <[hidden email]>
Sent: Sunday, December 07, 2003 9:03 AM
Subject: RE: Simple AI Scripting, Help Me!


> Can you provide a short example script that shows what you want to be
> able to?
>
> It doesn't have to be proper lua, just something that shows what you are
> trying to achieve.
>
> > Thanks for you help, I really appreciate it, my only question
> > now is I need to call a function everyframe to update a dudes
> > position or state (every frame or every 5 or whatever).  Not
> > sure how I would do this with this example below.  How would
> > it tie in with my player class etc.  I don't want to really
> > expose a whole players class (from lua), nothing if I can
> > help it. I want the scripts to be really high level, so
> > anyone could write scripts for it.  I don't want to write the
> > scripts myself, I want to set them up, and hand them off to
> > some else who doesn't have much knowledge of programming (if
> > need be).  So I don't really want it to look like c++, or c
> > (lua does resemble it), just they way one would think
> > enemyclose(), runforcover(), seekhealth(), findescort(), etc
> > etc, and I expose those functions to lua.  If I load this
> > main.lua it will parse the whole thing, and stall my app, I
> > call it from my initfunction of my game, where is before, I
> > called a function to update a guy from c++, everyframe, and
> > returned true when it finished the function .. his goals.
> >
> >
> > Thanks,
> >
>


Reply | Threaded
Open this post in threaded view
|

RE: Simple AI Scripting, Help Me!

Kevin Baca-2
I'll point you back to Nick Trout's suggestion about co-routines:

http://lua-users.org/lists/lua-l/2003-12/msg00073.html

And also point out that a lua co-routine is the same as a lua thread
(see lua_newthread()).

You should also investigate lua environments.

A note about your architecture:  I think you might get into trouble
using the global variable "processingactor".  What if an entity's script
wants to call a function from another entity's script?

If your functions operate on an entity then, rather than operate on a
global variable, they should take the target entity as a parameter.

One more suggestion:  Try writing a small text-based prototype of your
game entirely in lua.  This will not only help you to learn lua, but
also give you a good idea of where the lua-C interface should be.

-Kevin

> 
> This is what I have now, it's very early yet, I just started, 
> and I have bounced things around trying to get this to work, 
> so it's not what I want in the end, but here it goes.  I have 
> a state machine, that for each state has an init, proc, exit, 
> and in my init for the main game state, I call the following.
> 
> mylua_Init();
> 
> looks like this at this moment ..
> 
> static lua_State * ls;
> 
> void mylua_Init()
> {
>      ls  = lua_open();
> 
>      if (NULL == ls) logger("Error Initializing Lua\n");
>      else
>      {
>             logger("Lua Initialized\n");
> 
>          lua_baselibopen(ls);
>       lua_iolibopen(ls);
>       lua_strlibopen(ls);
>       lua_mathlibopen(ls);
> 
>       lua_register( ls, "addNPC", fl_AddNPC );
>       lua_register( ls, "drawstring", fl_DrawString );
>       lua_register( ls, "drawnumber", fl_DrawNumber );
>       lua_register( ls, "getsceneframe", fl_GetSceneFrame );
>       lua_register( ls, "findsetlocation", fl_FindSetLocation );
>       lua_register( ls, "keyhit", fl_KeyHit);
>       lua_register( ls, "setframe", fl_SetSceneFrame);
> 
> }
> 
> sorry bout the spacing, outlook has hosed my tabs, then I call
> 
> mylua_Load("dam.lua");
> 
> which looks like this ...
> 
> void mylua_Load(const char *scriptname)
> {
>  pushandsetdir("scripts");
>   lua_dofile(ls, scriptname);
>  popdir();
> }
> 
> 
> dam.lua looks like this(looks familor right? :) )
> 
> local Hero = assert( loadfile( "hero.lua" ) )()
> local GuardGuy = assert( loadfile( "guard01.lua" ) )()
> 
> function createHero()
>    return setmetatable( {}, { __index = Hero } )
> end
> 
> function createGuardGuy()
>    return setmetatable( {}, { __index = GuardGuy } )
> end
> 
> Hero = createHero();
> 
> Hero:doSomething()
> 
> 
> 
> this works fine but it's not what I want, want I had before 
> was I would create a hero like this
> 
> MOBHuman *thisguy;
> 
> thisguy = addchar(0,0,0,actorlist);
> 
> then I would load a file like ...
> 
>  mylua_Load("heroscript.lua");
> 
> then in my main loop I would call
> 
> void MOBHuman::Processplayer()
> {
> 
>             which would update the guys position keyboard 
> input , etc etc.
> 
>             I would also call something like mylua_aiprocess(this);
> 
>             which looked something like this..
> 
>             void mylua_aiprocess(MOBHuman *curactor) {
> 
>                     int val;
> 
>                    // I stored the current actor passed in so 
> that all the exposed functions of my game knew which was the 
> current guy
> 
>                 processingactor = curactor;
> 
>                  lua_getglobal(ls, "playerprocess");
> 
>                  lua_call(ls, 0, 1);
> 
>                 // so that when it called something from lua 
> like here is my old scipt I was using
> 
>                 function playerprocess()
>                      local rvalue = 0
> 
>                      if ( keyhit("DIK_SPACE") > 0 ) then
>                           --drawstring(-1,30,"hit spacebar")
>                           setframe(4099,1) -- framenumber, 
> continue playing
>                      end
> 
>                      if ( 
> findsetlocation("herostart.mxo",1,0) ) then  -- 
> lookfor, setposition, setrotation
>                           --drawstring(-1,30,"haha found something")
>                         else
>                           --drawstring(9,30,"ouch didn't find it")
>                      end
> 
>                      if ( getsceneframe() > 4100 ) then
>                           findsetlocation("dockstart.mxo",1,1)
>                           rvalue = 1;
>                      end
> 
>                         return rvalue
>                 end
> 
>                 again this loop was called every frame of my 
> game proc, what this script did was basically take over all 
> input of my game, and force him to an object
> 
>                 that moved in the world until frame 4101 or 
> whatever, then it would bail out, and I would then not call 
> this function any more, this was sorta a hack to get something
> 
>                 working, I planned on revising this, and 
> building from it, when I started having problems with 
> multiple players, having their own scripts.  the idea here 
> was that when a function was
> 
>                 called from lua like this ..
> 
> 
> 
>                     int fl_FindSetLocation( lua_State * luaVM ){
> 
>                                 // I could use 
> processingactor in here, and it would know from(in theory) 
> when it called from lua, that it was dealing with processingactor
> 
>                                 // this is also when I 
> starting having trouble when I added another guy into the 
> world, and created him and loaded his file, which has the 
> same function name in lua as the hero guy playerprocess, since
> 
>                                   // I guess there was only 
> one lua_State it was using the latest playerprocess function 
> for all guys
> 
>                    }
> 
> 
> 
> Hope this isn't too complicated to understand, not even sure 
> the best ways to do things in lua, I almost wrote my own 
> scripting language, when I realized I didn't want to
> 
> re-invent the wheel (so to speak), and lua I stumbled across, 
> from a company who didn't make it  and decided to opensource 
> the whole engine, and source, and binary to
> 
> http://catmother.sourceforge.net/  which I applaud them for, 
> and I have looked that the stuff they have, but it's a wild 
> goose chase trying to figure out what was going on.
> 
> which sometimes is why I hate c++.  Anyways what I what is a 
> highlevel scipting language with calls that pretty much do 
> all internal stuff within
> c++, and I decide
> 
> what to do with the results given back from my game.  In 
> order to do this, I need to be able to have my game call lua 
> basically every frame (maybe every
> few) (for characters and other scritables)
> 
> to update the status of things.  Of couse with anything you 
> need a foundation to build from, and my foundation has 
> termites (at the moment) thats why I look here for help, I 
> appreciate it.
> 
> Tim Ryness
> 


Tim
Reply | Threaded
Open this post in threaded view
|

Re: Simple AI Scripting, Help Me!

Tim
I don't think I will ever want to call another script from another, we are
talking about have
a high level language here, and the fancier you make it, the more harder the
learning curve is.  Which makes me wonder how lua is going to work out for
me, the more deeper you go
into lua, the harder it becomes for people to digest, I'm starting to hate
lua actually, I see
some stuff on coroutines, but it really doesn't help me to get them working,
honestly I don't
really know where to begin with them, you can read all you want, but I want
to see someone implement them in something besides a lua script, see how c++
and lua work with
them together, why are all the damn samples in scripts?  The best help I
found was from sample programs from like gamsutra, and the likes.  I can see
how they use lua and intergrate with c++, except they stop short of what I
want.  I can see the power in lua for loading level assets and other stuff
for configurations and all sorts of init stuff.  I have failed to see it
work for what I want.  I know it can be done, and I has been done, but I'm
running out of time to mess with this stuff, I have so much other stuff to
do, I didn't want to spend my time banging my head against the wall, looking
through piles of docs, and messages, only to get nothing, why is something
so seemly easy to want, seem so difficult to implement?  I don't know, I
guess I have better thangs to do, like re-invent the wheel or something.
I'll leave you with this sample..


Simple usage
To create a coroutine we must have function which represents it, e.g.,

> function foo()
>>   print("foo", 1)
>>   coroutine.yield()
>>   print("foo", 2)
>> end
>
We create a coroutine using the coroutine.create(fn) function. We pass it an
entry point for the thread which is a Lua function. The object returned by
Lua is a thread:

> co = coroutine.create(foo) -- create a coroutine with foo as the entry
> = type(co)                 -- display the type of object "co"
thread
We can find out what state the thread is in using the coroutine.status()
function, e.g.,


> = coroutine.status(co)
suspended

wtf is co? this isn't surely called from c, it's called within lua right?
is co? lua_State * co?  I hate to be so down on this, but It is so
frustrating to work on something that has so much promise, and investsome
hard hours to get nothing yet.I do appreciate all your help, I know you owe
nothing to me, and you have answered my emails over the weekend, I
appreciateall the support.Tim Ryness


Reply | Threaded
Open this post in threaded view
|

Re: Simple AI Scripting, Help Me!

Robert Anderberg
Hi Tim,

First of all, I'd like to suggest that sometimes as a programmer you will have to bang your head off something for a while before it clicks. Lua is worth investing some time in, but you can't expect to learn a complete language in a few of days (I've been using Lua for a few years and still find new ways of implementing things regularly).

The Lua manual is quite like a Bjarne Stroustup C++ book. It's very terse, but all the information is there is you take time to read it. You should also read the Lua book (available on the website in .pdf and .ps formats).

From reading through your (extremely verbose) mails, I gather that you want to have multiple game entities controlled by Lua scripts that deal with their decision making and movement. As in Extreme Programming, it's often useful to do the simplest thing that works and work from there.

The last game we wrote did exactly this and basically follows the simple object oriented ideas described in the Lua book

This is how we did it:

Objects are created in Lua that have pointers to c++ objects. Each object has an init() tick() and destroy() function. When an object is created, the resources for the object are loaded and a pointers are returned and stored in the Lua object, the object's init() function is called, and the tick() function is created as a coroutine. Each frame we iterate over all the objects resuming their tick coroutines, they do some processing (calling host functions) then yield. Objects are destoryed explicitly at which point their destroy() function is called.

That's it, it's really simple and works well.

I would also suggest that you try to be more concise in your postings, It's much easier to help when there's a clearly defined question ;)

Rob


Reply | Threaded
Open this post in threaded view
|

Re: Simple AI Scripting, Help Me!

Enrico Colombini
On Monday 08 December 2003 12:46, Robert Anderberg wrote:
> The Lua manual is quite like a Bjarne Stroustup C++ book.

I hope you didn't mean that as an insult to the manual's authors :-)
Both as a C++ programmer and as a professional courseware writer, I consider 
"The C++ programming language (3rd ed.)" a monumental failure. It is useless 
as an introductory course, and worse than useless as a reference (I may take 
some of this back if you were referring to "The annotated C++ reference 
manual", but you'll notice there is another author beside B.S.).

> It's very terse, but all the information is there is you take time 
> to read it.

Oh, you meant "like a Kernighan-Ritchie book" :-)

The above rant is my way to say that the Lua reference manual is one of the 
best language manuals I read. On that I think we agree.

  .Erix.


Reply | Threaded
Open this post in threaded view
|

RE: Simple AI Scripting, Help Me!

Virgil Smith
> Oh, you meant "like a Kernighan-Ritchie book" :-)
>
> The above rant is my way to say that the Lua reference manual is one of
the
> best language manuals I read. On that I think we agree.

My $0.02.
The Lua Manual is extremely well written, both as an introduction to the
language and as a reference.  It introduces the language features (and most
of the motivations) while staying very short and to the point.  It's brief
enough to be a very good reference, but written in a readably organized
fashion.

There is only 1 caveat to the manual that I would recommend to beginners.
This is a "process for learning from the manual".
1. Read the manual all the way through.
2. Read the manual all the way through.
3. Now sit back and think about what you can do with the language features.
4. Now, read the manual all the way through.
5. Now sit back and think about the motivations behind the language features
and how neatly they fit together.
6. (Optional) Go write up some code snippets, bounce around in the manual
checking details, (very optional) dance around with glee, rub your hands
together and form a malicious grin thinking about all of the things you can
do with this tool and how easy it will be to slip into whatever you are
working on.  (Optional, culturally dependent, and getting terribly silly at
this point) Ponder the universe and the fundamental nature of human beings
that somebody would just give away something so amazingly useful and
coherent.  Express this through religious activism, donations to
humanitarian societies, and long yoga meditation exercises performed in the
glow of your monitor.
7. Now, read the manual all the way through.
8. Now, go carefully inspect the code for the auxiliary library and take
mental notes to yourself on how you will want to use these functions in your
own applications.


Reply | Threaded
Open this post in threaded view
|

RE: Simple AI Scripting, Help Me!

Reuben Thomas-5
> There is only 1 caveat to the manual that I would recommend to beginners.
> This is a "process for learning from the manual".
> 1. Read the manual all the way through.
> 2. Read the manual all the way through.
> 3. Now sit back and think about what you can do with the language features.
> 4. Now, read the manual all the way through.
> 5. Now sit back and think about the motivations behind the language features
> and how neatly they fit together.
> 6. (Optional) Go write up some code snippets, bounce around in the manual

This is not optional. It should be inserted before each of your steps
(step 0 alone being optional, in case you've not programmed much before,
or prefer to know the language a bit before using it).

-- 
http://www.mupsych.org/~rrt/ | humour, n.  unexpected recognition

Reply | Threaded
Open this post in threaded view
|

Re: Simple AI Scripting, Help Me!

Mauricio Oliveira Carneiro
In reply to this post by Virgil Smith
There is only 1 caveat to the manual that I would recommend to beginners.
This is a "process for learning from the manual".
1. Read the manual all the way through.
2. Read the manual all the way through.
3. Now sit back and think about what you can do with the language features.
4. Now, read the manual all the way through.
5. Now sit back and think about the motivations behind the language features
and how neatly they fit together.
6. (Optional) Go write up some code snippets, bounce around in the manual
checking details, (very optional) dance around with glee, rub your hands
together and form a malicious grin thinking about all of the things you can
do with this tool and how easy it will be to slip into whatever you are
working on.  (Optional, culturally dependent, and getting terribly silly at
this point) Ponder the universe and the fundamental nature of human beings
that somebody would just give away something so amazingly useful and
coherent.  Express this through religious activism, donations to
humanitarian societies, and long yoga meditation exercises performed in the
glow of your monitor.
7. Now, read the manual all the way through.
8. Now, go carefully inspect the code for the auxiliary library and take
mental notes to yourself on how you will want to use these functions in your
own applications.

... and after that, watch the excellent LUA classes given by Roberto at PUC-Rio. :-)

--
Mauricio Oliveira Carneiro
http://www.tecgraf.puc-rio.br/~carneiro
FIOCRUZ - PROCC

Reply | Threaded
Open this post in threaded view
|

RE: Simple AI Scripting, Help Me!

Nick Trout
In reply to this post by Tim


> The above rant is my way to say that the Lua reference manual is one
of
> the
> best language manuals I read. On that I think we agree.

I agree too. I like the terse nature of it. I rarely spend a lot of time
looking for something and a few small experiments usually clarify any
misunderstanding on my part.

If you feel that the manual is not verbose enough I suggest you try
reading the tutorial:

	http://lua-users.org/wiki/LuaTutorial

	http://lua-users.org/wiki/TutorialDirectory

The style of the tutorial is supposed to be more chatty and fluid than
the manual, with plenty of examples to demonstrate and clarify any
concepts discussed. If you feel the tutorial is not clear or lacking in
someway then you should leave a comment so we can address this:

	http://lua-users.org/wiki/TutorialComments

I know the C API section is still missing from the tutorial. I will try
and address this in the near future. More generally it seems a section
on binding, and practical application of co-routines and environments
would be appropriate. I think I've noticed a drop in traffic for basic
"how do I do this" questions from newbies in Lua. I think the increased
documentation in the community has had an effect but we still have a way
to go.

Nick


Tim
Reply | Threaded
Open this post in threaded view
|

Re: Simple AI Scripting, Help Me!

Tim
If I had the time, this is all predicated on time, which I have nill.  We
have like a short
time to do a game, we don't have much staff to work this game, we have most
of an engine
I have little to no gameplay, I wanted to use lua to help get gameplay fast,
then offload
the scripting to someone else who can read a sample script I provide, and be
good to
add other things, and basically bug me about exposing more functions, I
don't have the
time to read lua manual 45 times, and sit back and drink a beer, and read it
again, this isn't
rehab, what I want to do is so basic, it blows my mind.

what I want in simple form.

player 1 uses player1.lua
in the script there are 3 functions, init, proc, exit

player 2 uses player2.lua
in the script there are 3 functions, init, proc, exit

player3 uses player3.lua
in the script there are 3 functions, init, proc, exit

etc etc, get it?

init is called once in my game init.. it does whatever it needs to do, to
set up the player.

proc is called once per game frame, until game end, or player die etc.

exit is called once on exit

I would guess I would need co-routines, or muliple lua_states, how to I set
them up, THE BIG THING how do I interface them with my GAME to make them
work, you know how much time I have spent reading nothing but .lua files, I
don't care about how they work inside lua, I want to know how they work
together with my app, there is plenty of good documents on the scripting
langauge itself, I can figure that out, but there is little or no
documentation on interfacing it with your app.




Reply | Threaded
Open this post in threaded view
|

Re: Simple AI Scripting, Help Me!

Jared Krinke
> I would guess I would need co-routines, or muliple lua_states, how to I set
> them up, THE BIG THING how do I interface them with my GAME to make them
> work, you know how much time I have spent reading nothing but .lua files, I
> don't care about how they work inside lua, I want to know how they work
> together with my app, there is plenty of good documents on the scripting
> langauge itself, I can figure that out, but there is little or no
> documentation on interfacing it with your app.

Did you read the 3rd section of the manual? If you've got a basic
understanding of stack manipulation and you read all of the 3rd section
you should be all set to make a scripting interface.

Yes, there are some tricks to it. Here's basically what I came up with
after trying things:

The actual objects themselves should be created with lua_newuserdata so
that the memory management is handled by Lua. You shouldn't delete stuff
with the class's destructors, rather use the __gc metamethod in the
userdata's metatable.

Immediately after getting the new userdata object, I add a few things to
its metatable (handlers for __index and __newindex mostly) to give
access to the variables that are stored in the C data structure (x, y,
size, etc. in my case).

If you need to store global C state, use the table at LUA_REGISTRYINDEX.
(I use this since I'm writing in C and need basically a void* data).

Every frame, I iterate through the list of entities (which I store in a
linked list in C) and then I use lua_pcall on the userdata's "update"
function, giving the userdata and the time passed as parameters.

That's about all there was to it. The hardest part for me was figuring
out that Lua wants to memory manage everything (which makes sense).
Although it's somewhat possible to manipulate C structures that weren't
created by Lua, it is much easier to just use userdatas all over the
place.


Reply | Threaded
Open this post in threaded view
|

Re: Simple AI Scripting, Help Me!

Nicolas Noble
> > I would guess I would need co-routines, or muliple lua_states, how to I set
> > them up, THE BIG THING how do I interface them with my GAME to make them
> > work, you know how much time I have spent reading nothing but .lua files, I
> > don't care about how they work inside lua, I want to know how they work
> > together with my app, there is plenty of good documents on the scripting
> > langauge itself, I can figure that out, but there is little or no
> > documentation on interfacing it with your app.
>
> Did you read the 3rd section of the manual? If you've got a basic
> understanding of stack manipulation and you read all of the 3rd section
> you should be all set to make a scripting interface.

I would also add that you should read the libraries code. For example, in
the file lmathlib.c, or lbaselib.c, you will find plenty of examples of
use.


123