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 ➜ SMAUGFUSS Addition of Lua

SMAUGFUSS Addition of Lua

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


Posted by Keirath   (10 posts)  Bio
Date Sat 27 Apr 2019 01:13 PM (UTC)
Message
So, I've read several things (years old now obviously) about people working on Lua implementation and most of what I've seen that was released is incomplete.

I'm interested in entirely replacing mudprogs with Lua so I was wondering if anyone has successfully and completely done this on SMAUG. This is really outside my knowledge on coding as everything I know is from MUD coding. Frankly, I know C and C++ in a very hackish way and have no understanding of Lua, but I'm willing to teach myself if anyone has any advice as well.

I'd love to be able to use Lua to completely script mobs and generate way more intelligent quests etc.

Also: is it possible to have Lua access C functions? For instance, when you script something in Lua, would it be possible to have it use the gain_exp function exactly as it's written or does a Lua side function have to be written.
Top

Posted by Nick Gammon   Australia  (23,131 posts)  Bio   Forum Administrator
Date Reply #1 on Sun 28 Apr 2019 12:28 AM (UTC)
Message
I describe how to add Lua scripting here:

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

Quote:

Also: is it possible to have Lua access C functions? For instance, when you script something in Lua, would it be possible to have it use the gain_exp function exactly as it's written or does a Lua side function have to be written.


No, Lua needs certain calling conventions. You basically have to make "glue" functions to interface between Lua and C. MUSHclient does that, for example, to make the Lua interface similar to the VBscript (etc.) interface.

I describe the general idea here:

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

For example:


static int miles_to_km (lua_State *L)
  {
  double miles = luaL_checknumber (L, 1);
  double km = miles * 1.609;
  lua_pushnumber (L, km);
  return 1;   /* one result */
  } /* end of miles_to_km */


The Lua function needs a single argument (the Lua state) and inside the function you get the Lua arguments (luaL_checknumber for example). Then you do stuff, and push results (eg. lua_pushnumber).

Finally you have a table of all the functions you are exposing in this way, and "register" it with Lua.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


10,275 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.