The problem:
I had a variable arguments function set up to pass internal C variables along to the scripting system. As a consequence, values could be any type, including int, float, long, double, or even a custom struct used to pass object handle data (ie a ship handle).
Or in other words, take this:
void script_state::SetHookVar(char *name, char format, void *data)
and pass the data to this:
int ade_set_args(lua_State *L, char *fmt, ...)
However, ade_set_args was a lowlevel API function. It couldn't be used by any other part of the code to set global hook-specific variables (eg hv.Player) outside of the lua code itself, and I needed that high-level function call in order to be able to pass variable data along to the scripting system in other parts of the code. Unfortunately, I couldn't get the varargs working inside of a function inside of another varargs function and still have the lower-level function be usable by other parts of the code.
The solution:
Cheat. By casting the pointer to ade_odata (the custom struct) and then dereferencing it, I instructed the compiler to always copy that much of the stack for the function to use. Since float, double, etc are all smaller than the custom struct, they'll always be copied along (with a bit of garbage). As long as the format string is set correctly, the compiler only uses the proper amount of stack space.
ade_set_args(LuaState, fmt, *(ade_odata*)data)
To this day, I haven't heard of any problems.