lua embedded example

Posted by Llarn on Tue 06 Jan 2009 07:22 AM — 6 posts, 34,551 views.

#0
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
Australia Forum Administrator #1
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.
#2
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
Australia Forum Administrator #3
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?
USA #4
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.
USA #5
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.