SMAUGFUSS Addition of Lua

Posted by Keirath on Sat 27 Apr 2019 01:13 PM — 2 posts, 14,326 views.

#0
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.
Australia Forum Administrator #1
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.