Have we considered using SWIG to do the interface between lua and code.lib? If so, why do we not?
if it can do what we have now without changing too much stuff, maybe. id only be concerned that it would make scripting a little bit more complicated, you would have to have some foreknowledge of the engine internals to write effective script. the current scripting system really doesnt require any info about the engine internals. on the other hand it would mean that we wouldnt need to write a 15 line proxy function in c for every new piece of data we needed (and possibly a smaller cpp file).
Yes, it will make you closer to the engine internals, and it does expose how horribly documented the some of the interfaces in the engine actually are, but it would give Lua instant access to all the systems in the code, with the same abilities to modify the engine behaviour that the C* code can. The poor documentation of the interfaces is something that needs to be addressed in the C* code anyway, so, this may or may not spur some activity in fixing the documentation, which would then help both the C* and Lua coders at the same time.
Honestly, we have the same problem with the SEXP system as well, a well defined interface that is visible to the FREDer, but you step behind the curtain you see the C* code that has no documentation at all. But I digress, as the documentation thing is a pandemic in the engine.
Also, SWIG wouldn't replace the current lua interface, at worst it would make it a depreciated interface. We could also potentially re-implement the wrapper functions that are contained in lua.cpp in pure lua using the SWIG interface. Using the pure lua library would be able to insulate the Lua coder from limited changes in the C interface. The library would also allow some more object oriented interfaces for the lua coders for some of the very C like interfaces in the engine.
I am attaching a discussion I had with The_E on the topic on #SCP (I have stripped out the off topic discussion that was going on at the same time). Some of it repeats what I have already written here.
(2:14:15 PM) The_E: IssMneur: http://www.hard-light.net/forums/index.php?topic=44821.msg1408106#msg1408106
(2:14:18 PM) The_E: Errrm
(2:14:55 PM) The_E: We haven't considered it because, for all intents and purposes, lua is part of code.lib already.
(2:16:47 PM) IssMneur: well, not really, its in code.lib, but its not part of code.lib
(2:17:08 PM) IssMneur: lua is basically in the house but looking from the side of the room
(2:17:36 PM) The_E: IssMneur: Point is, why introduce another indirection layer between lua and the rest?
(2:19:01 PM) IssMneur: The_E: it wouldn't add another indirection layer, it would replace the current indirection layer
(2:19:40 PM) The_E: Which layer would that be, then?
(2:20:27 PM) IssMneur: The_E: the layer that we call lua.cpp
(2:21:14 PM) The_E: IssMneur: And what net benefit would we gain from replacing it?
(2:23:06 PM) IssMneur: "automatic" access to all interfaces in the engine. You would have to enumerate the functions or tell swig to include the header files that are used as external interfaces.
(2:23:29 PM) IssMneur: but you would be able to use the same functions and the same code as the rest of the code does
(2:24:13 PM) The_E: Hmm
(2:24:16 PM) The_E: Interesting
(2:24:39 PM) The_E: No more dicking around with arcane hook variables etc
(2:24:44 PM) IssMneur: yep
(2:25:03 PM) The_E: Of course, that would also mean breaking all existing scripts if we introduced this, yes?
(2:25:12 PM) IssMneur: lua would become a first class interface just like the c code.
(2:25:32 PM) The_E: Unless we can find a way to preserve the current interface as well
(2:25:46 PM) IssMneur: ya, though, we could always just abandon the current interface as a "legacy" interface
(2:26:17 PM) The_E: Yes, of course. I just don't see removing that legacy interface as being an option
(2:26:36 PM) The_E: Too many big mods are already depending on it
(2:26:41 PM) IssMneur: and change the scripting hooks to cover it either at the .tbl level or at the lua level by putting all of the new stuff into namespaces
(2:31:09 PM) IssMneur: The_E: do you mind if I copy this discussion to the my post?
(2:31:24 PM) The_E: Not a problem
(2:31:29 PM) The_E: Hmm
(2:31:33 PM) The_E: One other thing
(2:31:59 PM) IssMneur: ?
(2:32:22 PM) The_E: The current lua interface is very good for us, because it includes documentation for the lua API, which can be spewed to file using -output_scripting
(2:33:38 PM) The_E: Without something like that, you'll just end up with lots and lots of wrapped, but undocumented functions
(2:33:52 PM) IssMneur: ya, basically
(2:34:05 PM) The_E: That's terribad
(2:35:44 PM) The_E: Also, nuke just raised a very good point
(2:35:51 PM) IssMneur: but because the functions are the same functions that the C code uses the documentation for them would be exactly the same, and the C functions that don't have any documentation need documentation written for them anyway. With swig you are killing two birds (documenting the C/C++ interface, and the lua interface at the same time)