23 Jun, 2009, Silenus wrote in the 1st comment:
Votes: 0
I have been toying around with the idea of building a lua-like mud server and I had a few questions about information I cannot glean from the reference manual. I anyone can help me with these I would appreciate it:

1) What exactly are tables and what can you do with them?
2) What are the implications of metatables?
3) is there a body of lua code out there which I can look at to get a sense of how the language is typically used?

Thanks in advance.
24 Jun, 2009, tphegley wrote in the 2nd comment:
Votes: 0
Check out Nick Gammon's site. He made a lua mud server.

http://www.gammon.com.au/forum/bbshowpos...
24 Jun, 2009, David Haley wrote in the 3rd comment:
Votes: 0
1) A Lua table is a map from keys to values. As for what you can do with them, well, any data structure can be represented with tables, so you can do basically whatever you want with them.
2) I don't know what you mean by "implications of metatables". A metatable on table t specifies what to do when a given thing is requested of or performed upon table t. As such, metatables let you redefine a huge portion of the straightforward language semantics.
3) I can't point you to anything in particular as a "poster child" example of how to use Lua. WoW uses Lua extensively; MUSHclient uses Lua extensively as tphegley mentioned; if you poke around on Google you will find lots of examples.
24 Jun, 2009, Silenus wrote in the 4th comment:
Votes: 0
I will download that server code and look at it. I probably should have done a bit more googling before asking. I didnt realize there is also a programmers guide online(I thought they would force me to buy a book). It will probably answer some of the questions I cannot deduce from the reference which just seems to primarily describe the grammar. Thanks
24 Jun, 2009, David Haley wrote in the 5th comment:
Votes: 0
The reference describes the syntax and semantics very concisely, it's just that it doesn't make it obvious how to write code. The PiL book is much better for that, and both are available for free online. (PiL2 has to be purchased.) That said, it's one of the best language references I've ever seen, and IMO vastly superior to e.g. Python in describing very precisely the semantics of operations like lookup. (Can you point me to a clear description of the precise sequence of events that occur when you execute 'a.foo' in Python?)
24 Jun, 2009, Silenus wrote in the 6th comment:
Votes: 0
I was basically having some problems deducing the full implications of tables from the reference(i.e. how OOP works and things like SI/MI). I am basically just curious what you can do with this mechanism as it is defined in Lua. I dont really know much about Python. I suspect I have a dated reference on my shelf somewhere (which I havent looked at in years).
24 Jun, 2009, David Haley wrote in the 7th comment:
Votes: 0
Again I'm not sure what you mean by data structures "implying" things. Lua does not provide OOP mechanisms explicitly, however you can easily recreate OOP using metatables; just search for "Lua OOP" – you'll probably find something called "LOOP", IIRC, which shows how to implement several OOP schemes using Lua.

If you understand OOP fairly well and are aware of various implementations of OOP in different languages, it should be pretty clear how metatables let you intercept events in ways that let you replicate OOP. That's what metatables are, really: ways of intercepting events.

By overriding what happens when you read something from a table, or write to it, you can define a huge number of things; OOP is a relatively simple usage of metatables.
30 Jun, 2009, JohnnyStarr wrote in the 8th comment:
Votes: 0
So, i know this has been discussed a ton, but since noone has embedded Lua in ROM (that i know of) should i follow the instructions for Nick Gammon's SMAUG / Lua tutorial step by step and post the errors i get?

I'm starting to see that Mobprogs can be difficult but i dont want to give up on having scripting in my mud, any thoughts? Are there any books that walk through this kind of process? I mean, i've read a walkthrough to do simple things like print("This is Lua in C") kind of stuff, but when were talking about accessing and changing the state of C Data Structures ETC its quite allot.
30 Jun, 2009, David Haley wrote in the 9th comment:
Votes: 0
If you poke around on Nick's site, you'll find that I disagree with his approach of embedding Lua, as, while it allows a great deal, it basically kills the possibility of using Lua to implement a superior "mudprog" scripting language. (The gist of it is that you need a global state with characters as first-class objects, not one state per character. In fact, you'll see that Nick uses a global state to implement things like resets.)

And yes, life gets really interesting really fast when trying to do a full embedding, but, well, that's kind of the way it is. I have a lot of code written to do just this kind of embedding in Darkstone, and I hope to release it one of these days as an example. 'course, it's for a heavily modified C++ codebase that often bears little resemblance to SMAUG… but it shows the concepts.
01 Jul, 2009, elanthis wrote in the 10th comment:
Votes: 0
Sounds like he could've just used coroutines instead of separate states to get the same effect without losing any functionality.

He might have originally designed his Lua implementation before it had coroutine support, though.
01 Jul, 2009, David Haley wrote in the 11th comment:
Votes: 0
No, coroutines existed. He explicitly didn't want to embed Lua such that characters etc. were first-class objects, because you get nasty issues with garbage collection etc. if you're not very careful, and IIRC he didn't want to deal with that at the time.
0.0/11