Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ SMAUG ➜ Lua ➜ Version 2 of the Lua interface released

Version 2 of the Lua interface released

It is now over 60 days since the last post. This thread is closed.     Refresh page


Pages: 1 2  

Posted by Nick Gammon   Australia  (23,057 posts)  Bio   Forum Administrator
Date Sun 15 Jul 2007 11:37 PM (UTC)
Message
I have now released version 2 of the Lua interface to SMAUG (1.49 Mb):

http://www.gammon.com.au/files/smaug/smaug17fuss_lua_v2.tgz

Md5sum is: 6b237f81c8f3620c6da6b598c5be74f0

This incorporates quite a few improvements to the Lua interface, the updated functions are listed here:

http://www.gammon.com.au/forum/?id=8015

It also incorporates the new resets system described here:

http://www.gammon.com.au/forum/?id=8027

An example of doing the resets for Darkhaven Academy is provided in the download.




The various Lua files (in the lua directory) and their purposes are:


  • resets.lua

    Code to reset an area. Has an example for Darkhaven Academy.

  • serialize.lua

    Standard table serialization (same as used in MUSHclient) - converts a Lua table into a string, suitable for saving to disk. Used for saving player states.

  • startup.lua

    File loaded at player connect time (once per player). This implements the various things needed for players (eg. task system, whereis system, hints).

    Most of this is in modules loaded by startup.lua.

  • startup_mud.lua

    File loaded a MUD startup time. This implements the resets system (by loading a module).

  • taskevents.lua

    Event handlers for the task system. This responds to things like the player entering a room, killing a mob, receiving an item, and so on.

  • taskhints.lua

    Functions to give the player hints. These are called from various hook points (eg. entering a room, completing at task), to make suggestions. Once a hint is given a flag is set in the player state file so it isn't given again.

  • tasklist.lua

    Example tasks for the task system (list of tasks). This is a table, where each task is a sub-table.

  • tasks.lua

    Task system. This handles the "task" command (which is called from the SMAUG "task" command handler).

    Loads tasklist.lua, taskevents.lua, and taskhints.lua as sub-modules.

  • tprint.lua

    Debugging utility for displaying the contents of a table, recursively.

  • utilities.lua

    Various utility functions (like rounding numbers, formatting the time).

  • whereis_destinations.lua

    Table of places you want the player to be able to go to when using the "whereis" command. Just edit this and add new locations. Each zone has its own entry, so you might make an entry per town.

  • whereis.lua

    Implements the "whereis" command by working out the path from the player's current location to a desired destination.





The various additional source files (in the src directory) are:


  • lua_bits.c

    Bitwise functions.

  • lua_commands.c

    My initial attempt to make a Lua function for each SMAUG command. Not being used right now.

  • lua_scripting.c

    Implements the Lua script interface.

  • lua_tables.c

    Implements constant tables. At present, maps "at" colours and object types.

    eg.

    at.red returns AT_RED (9)
    itype.bloodstain returns ITEM_BLOODSTAIN


  • mt19937ar.c

    Code for the Mersenne Twister psuedo-random number generator.



- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,057 posts)  Bio   Forum Administrator
Date Reply #1 on Mon 16 Jul 2007 01:11 AM (UTC)
Message
To compile under Cygwin, see my post on this page:

http://www.gammon.com.au/forum/?id=8000&page=3

You need to make sure you have Lua installed, and copy the Lua header files to an appropriate place.

There is also a bit of tweaking of the lua_bits.c file.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,057 posts)  Bio   Forum Administrator
Date Reply #2 on Tue 17 Jul 2007 12:06 AM (UTC)
Message
As mentioned in this post:

http://www.gammon.com.au/forum/?id=8033

I have now released an updated version, which compiles more cleanly under C++. Basically it functions the same as version 2.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Gatewaysysop2   USA  (146 posts)  Bio
Date Reply #3 on Tue 17 Jul 2007 03:14 AM (UTC)
Message
Hey Nick!

Thanks again for your continued efforts with this. I've had much luck integrating this latest version in place of your first offering, and so far so good. I have an older version of FUSS (branched off FUSS 1.4a and manually bug fixed since!) but it wasn't too hard to get things working again.

I did notice one thing though, and that's with hotboot. Seems like Lua doesn't want to work following a hotboot, at least not until you log out and back in. I'm thinking the fix for this should be simple and will play around with it. Just wanted to mention it though in case nobody else had brought it up.

Other than that, no issues yet.

Thanks again for all the hard work on this and for sharing it so freely with the community.


"The world of men is dreaming, it has gone mad in its sleep, and a snake is strangling it, but it can't wake up." -D.H. Lawrence
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #4 on Tue 17 Jul 2007 03:25 AM (UTC)
Message
That would probably be easier to handle with a single global state, and not one state per player. It'd be less data to shuffle around. Still, I think the solution would probably just be to write out the player state's state (as it were) on copyover and read it back in on restart.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Nick Gammon   Australia  (23,057 posts)  Bio   Forum Administrator
Date Reply #5 on Tue 17 Jul 2007 05:28 AM (UTC)

Amended on Tue 17 Jul 2007 05:30 AM (UTC) by Nick Gammon

Message
Quote:

Thanks again for all the hard work on this and for sharing it so freely with the community.


You are welcome. I am glad someone is trying it and getting it to work.

I hadn't addressed the hotboot issue, are you saying the Lua state is not initialized? ... or that the script isn't read back in or something? I would guess that around here (near the end of hotboot.c) you need to insert a few lines:


         char_to_room( d->character, d->character->in_room );
         act( AT_MAGIC, "A puff of ethereal smoke dissipates around you!", d->character, NULL, NULL, TO_CHAR );
         act( AT_MAGIC, "$n appears in a puff of ethereal smoke!", d->character, NULL, NULL, TO_ROOM );
         d->connected = CON_PLAYING;


         open_lua (d->character);  /* fire up Lua state */
         call_lua (d->character, "reconnected", d->character->name);



That would force the Lua state to be opened (loading the script file) and the "reconnected" call makes it reload the character state file.

Let me know if that works, and I'll add it into the distribution.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Gatewaysysop2   USA  (146 posts)  Bio
Date Reply #6 on Tue 17 Jul 2007 06:06 AM (UTC)
Message
Looks like that works just fine. I had already added a call in that spot to open_lua, but I had omitted the reconnected stuff.

One thing I wanted to point out. I was wondering why the message in the mud-wide lua file wasn't getting echoed on boot-up. I think it was because in lua_scripting.c, you required an argument and a function name for call_mud_lua, instead of just requiring a function name (it seemed like argument was optional, further down?). I changed that and now it works.

Gotta run, getting late. :-/

Thanks again for all your help Nick!

"The world of men is dreaming, it has gone mad in its sleep, and a snake is strangling it, but it can't wake up." -D.H. Lawrence
Top

Posted by Nick Gammon   Australia  (23,057 posts)  Bio   Forum Administrator
Date Reply #7 on Tue 17 Jul 2007 07:06 AM (UTC)

Amended on Tue 17 Jul 2007 07:07 AM (UTC) by Nick Gammon

Message
I got a bit carried away with my checks for NULL pointers.

In lua_scripting.c, near the bottom, change:


int call_mud_lua (const char * fname, const char * argument)
  {
    
  int nArgs = 0;

  if (!argument || !fname)
    return FALSE;


to:


int call_mud_lua (const char * fname, const char * argument)
  {
    
  int nArgs = 0;

  if (!fname)
    return FALSE;



Further down it checks if argument is NULL or not, and conditionally pushes it onto the Lua stack.

I think I added that extra check, wrongly, after testing if the message appeared.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,057 posts)  Bio   Forum Administrator
Date Reply #8 on Tue 17 Jul 2007 07:32 AM (UTC)

Amended on Tue 17 Jul 2007 07:34 AM (UTC) by Nick Gammon

Message
I started to wonder what would happen if you manually edited the player state file (eg. Nick.lua) and made a syntax error. The way I had the code written it would misleadingly report that the state file was not found. I would suggest changing the function 'reconnected' in startup.lua to read like this:


-- after player reconnects, load his/her state file
function reconnected (name)

  local f, err = loadfile (get_file_name ())
 
  if f then
    f ()  -- execute it
  else
    io.stderr:write (err .. "\n")
  end 
   
  for _, func in ipairs (handlers.reconnected) do
    func (name)  -- call each handler to let them know
  end -- for
 
end -- reconnected


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,057 posts)  Bio   Forum Administrator
Date Reply #9 on Tue 17 Jul 2007 10:50 PM (UTC)

Amended on Tue 17 Jul 2007 10:53 PM (UTC) by Nick Gammon

Message
When testing with FUSS 1.8, I noticed a small bug.

In tasks.lua, find the function get_mob_name_and_room. If the mob is not in the world the function mud.mobinworld returns false, not a count, so you can't compare it to 1. Change the lines in bold to read as follows:



function get_mob_name_and_room (vnum)

  local minfo = mud.mob_info (vnum)
  if not minfo then
    return "no mob " .. vnum
  end -- doesn't exist

  local count = mud.mobinworld (vnum) or 0
  if count ~= 1 then
    return capitalize (minfo.short_descr)
  end
  
  local room = mud.room (vnum, true)  -- which room is it in?

  return capitalize (minfo.short_descr) .. " in " .. mud.room_name (room)
 
end -- get_mob_name_and_room


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Gatewaysysop2   USA  (146 posts)  Bio
Date Reply #10 on Wed 18 Jul 2007 03:16 AM (UTC)
Message
I must say it makes me somewhat giddy to be able to edit code and just log back in to see the effect. Fun stuff. ;-)

"The world of men is dreaming, it has gone mad in its sleep, and a snake is strangling it, but it can't wake up." -D.H. Lawrence
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #11 on Wed 18 Jul 2007 03:17 AM (UTC)
Message
Welcome to the world of Lua. :-)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Orik   USA  (182 posts)  Bio
Date Reply #12 on Wed 18 Jul 2007 03:40 AM (UTC)
Message
Is there plans to be able to create the code from inside a buffer in game? IE desc's and such? That'd be cool, but what we have now just is so much fun to play with. I know it's going to just get better.
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #13 on Wed 18 Jul 2007 03:50 AM (UTC)
Message
I plan on doing that for large chunks of it, yes. But to be honest, it's just as easy (if not easier) to load up your file in your shell (if you have shell access), so it might be better to get into that habit.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Orik   USA  (182 posts)  Bio
Date Reply #14 on Wed 18 Jul 2007 03:55 AM (UTC)
Message
Yea, i've no problems with it. This tasklist file will be REALLY big once you start putting more tasks into it. Is that just how it goes or will there be better ways on down the line?
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


69,147 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.