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, confirm your email, resolve issues, 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.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ Lua ➜ lua embedded example

lua embedded example

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


Posted by Llarn   (23 posts)  Bio
Date Tue 06 Jan 2009 07:22 AM (UTC)
Message
Nick,

Can you post an example of how to embedd progs?

I saw the one example you have where inside the
prog you add something like...
call_lua( actor, "speech", txt );

I guess that would call speech, where would we go about
putting a check to see what the speech is when it is
called, and if it is the txt desired, the do the action
of the script.

Is it a matter of adding something like this in lua_scripting.c?
static int L_speech( lua_State * L )
{

CHAR_DATA *ch = L_find_character( L ); /* get character pointer */

lua_pushboolean( L, ch != NULL );

return 1;
}

I'm very confused on how to do it, and really getting scripting to work with progs is all I want with lua. I could really use help with an example to go by.

Thanks,

Llarn
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Tue 06 Jan 2009 07:10 PM (UTC)
Message
I'm not totally clear what you want to do here. First, he is a link to where I show how to call Lua code, from C, in general:

http://www.gammon.com.au/forum/bbshowpost.php?id=6400



  • Do you want to call Lua code from the C part of the server; or

  • Do you want to call some C code from the Lua scripting?


Perhaps an example would help. It's all pretty easy, but I don't want to answer the wrong question.

- Nick Gammon

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

Posted by Llarn   (23 posts)  Bio
Date Reply #2 on Wed 07 Jan 2009 03:29 AM (UTC)
Message
Well I read your lua scripting posts, and I guess I just still don't understand how to convert mobprogs to use lua.
I assume are regular editor for mobprogs still would be fine, and calls for lua must be in every mobprog. Not sure beyond doing that what would be next.

Llarn
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #3 on Wed 07 Jan 2009 04:09 AM (UTC)
Message
You want to convert all Smaug mobprogs to be Lua? This isn't a trivial task. The head coder at Aardwold (Lasher) did that, and I think that used up about two years of his life.

It isn't so much that Lua is hard to code for, but you need to have access to mob data in the mobprog (eg. hit points, level, class etc.) so this has to be made available to the Lua scripts. Then for each action a mobprog can take (eg. speech, movement, doing things in general) you would need to write a Lua handler. Individually each one is easy, but to convert everything is a whole lot (like hundreds) of easy things.

Don't get me wrong, I think it is a great idea. But when I considered doing it, I thought the time it would take didn't warrant it. Maybe contact Lasher and ask how much work it took him?

- Nick Gammon

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

Posted by Lasher   USA  (22 posts)  Bio
Date Reply #4 on Wed 07 Jan 2009 11:40 AM (UTC)
Message
Hi Folks,

Nick asked me to comment on this briefly.

The two years isn't quite correct for just the Lua conversion part, but it did take a *lot* of time and thankfully, due to the size of Aardwolf, we had a lot of players to help us redo the mobprogs in Lua - so one player would convert an area using some guidelines we published and another group would test it. I probably did about 30% of the areas myself and it took about about 2-3 months altogether. At this point, no new value was added to the game, this was to get the minimum functionality that the progs already had into the new code base. Since the first conversion we've been going back to areas and making them work the way we always wanted them to, and the two years is probably dead on here - it started last Summer and I doubt we'll finish this year.

We really had no choice as we were unable to use existing mobprog code. I don't know how many mobprogs Smaug has or how complex they they are, but as awesome as Lua is for scripting, if what you're trying to do is just replicate the existing progs but in Lua, it probably isn't worth it.

If you want to use Lua for newer and more elaborate progs then I'd definitely recommend that. If you're running Smaug anyway then your time is probably better spent on new scripts that actually add something new to the game.

If your question was really "How do I make this work for mobprogs?" more than "How do I convert all mobprogs", I'll have to refer you back to Nick on that on as we're not using the same codebase or implementation of Lua.

Good luck with it! Converting to Lua is one of the best things we ever did, but converting the existing mobprogs would absolutely not have been worth if it hadn't been something we had no choice but to do.
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #5 on Tue 20 Jan 2009 02:48 PM (UTC)
Message
I will have an example of a fairly deep embedding published "soon" (I still need to clean some things up). I haven't yet started with mudprogs, with I have a lot of the infrastructure ready to do that conversion.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
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.


26,855 views.

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.