[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  Lua
. . -> [Subject]  SMAUGFUSS Addition of Lua

SMAUGFUSS Addition of Lua

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


Posted by Keirath   (10 posts)  [Biography] 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.
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] 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
[Go to top] 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.


9,475 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]