push_script_string_length(buffer, buffer_length)
script_invoke_function("process_subrequest")
if buffer[0] == ZMP then
parse_zmp // tiny itsy bitsy handful of code
script_invoke_function_argv("process_zmp", argc, argv)
else
push_script_string_length(buffer, buffer_length)
script_invoke_function("process_subrequest")
end if
/* assumes buffer does not include the ZMP byte – adjust by +1 in two places accordingly if it does */
int argc;
const char *c = buffer /* +1 */;
if (buffer_length == 0 /* +1 */ || buffer[buffer_length - 1] != 0)
return error; /* empty/invalid ZMP command buffer */
lua_getglobal(lua_state, "do_zmp");
for (argc = 0; c != buffer + buffer_length + 1; ++argc) {
lua_pushstring(lua_state, c);
c += strlen© + 1;
}
if (lua_pcall(lua_state, argc, 0, 0) != 0)
error(lua_state, "zmp handler failed: %s", lua_tostring(lua_state, -1));
It would be a lot easier to use MSSP syntax, using ctrl-A (0x01) for variables and ctrl-B (0x02) for values. You'd grab a free telopt and assume that the client will deal with whatever it is that is transmitted. Like with MSSP you could define a list of default variables and define their behavior, so scripts could be created that would work for several mud servers. Could call it MSDP (Mud Server Data Protocol).
ZMP is a little too strictly defined to work well for a more open ended approach I think.