Lua; states, threads, libraries and memory layout

For a couple of years now I’ve been programming a lot in Lua. One of the things I had a hard time with was the relation between the states, threads (coroutines in Lua) and memory layout.  This is mostly simple when doing some basic scripting, but once you start writing C libraries or library bindings you really need to be aware of all the nitty gritty details. Now throw in some multi-threading and you’ll get yourself in trouble in no time, if you’re not careful.
Continue reading