Open herbertgithubaccount opened 3 months ago
https://effective-lua.dreamweave-mp.com
There's also this guide from the homie Yvan Cwyan put together for dreamweave, mostly meant as general lua guidelines.
oh that would be a good thing to mention as well. i'll add that to the list of points
The goal of these wiki pages would be to provide a general Lua guide, with the goal of only covering pure-Lua topics. This would make it useful for both openmw and MWSE lua mod authors.
I've outlined a few things that may be worth covering, but please feel free to suggest any other topics that should be discussed, and to offer suggestions on how things might be changed/improved.
The official Programming in Lua book can be very terse at times, and there could be benefit in creating a page that explains some core Lua concepts. It also uses Lua 5.0 syntax, which sometimes clashes with the changes made in Lua 5.1.
Here are some things that may be worth expanding upon in the MMW:
A list of useful references for further reading:
The documentation for Lua is pretty scattered, so it might be useful to gather them all in one place. This could include links to https://effective-lua.dreamweave-mp.com/ the Programming in Lua Book, and some parts of the openMW/MWSE wiki pages. Maybe even some Roblox stuff too.
Suggestions on how to set up an IDE environment
This is covered in the
Common Lua syntax/pitfalls
This would include things like: the intricacies of the
and
andor
statements. Stuff like:It could also include problems with table-packing, unpacking, e.g.:
Mentioning the difference between
local
andglobal
variables would also probably be nice. I've noticed that quite a few mods in the Lua mod repo useglobal
variables when they are probably intending to use local variables.Metatables
Metatables are pretty complicated, and I haven't seen that many nice guides on them. Having a dedicated section for metatables would probably be very helpful to some people.
OOP programming
The official guide suggests using the following syntax for OOP:
I've seen this design paradigm lead to many bugs that are difficult to track, and it's sweeping a lot of the intricacies of metatables under the rug. And this is just my opinion, but I think that making an object its own metatable is usually not the best approach, and can lead to a lot of ambiguity that is difficult to untangle.
This approach also blurs the lines between objects and classes: making a new object is the exact same thing as making a sub-class. It might be nice to propose a different design-paradigm in the wiki.
Explanation of
for
loopsThe under-the-hood implementation of
for
-loops is a bit complex. And some more detail would probably go a long way. The official Lua documentation has a dedicated chapter on this topic, but it may not be the most accessible.Explanation of
coroutine
The
coroutine
documentation is a bit backwards in my opinion: it starts out by explaining the most abstract, general-purpose use-case, and only then does it mention the least abstract, most-common use-case: callingcoroutine.wrap
. I think it would be useful to have an explanation of the usefulness ofcoroutine.wrap
, and then link to the official Lua documentation if people want to know more about the general-purpose use-case.