const char lua_ffi[] = "local ffi = require(\"ffi\")\n"
"ffi.cdef[[\n"
"struct memcell_values { const char *str; double num1; double num2; };\n"
"\n"
"typedef struct TEvent TEvent;\n"
"typedef struct TTrack TTrack;\n"
"typedef struct TIsolated TIsolated;\n"
"typedef struct TDynamicObject TDynamicObject;\n"
"typedef struct TMemCell TMemCell;\n"
"typedef struct memcell_values memcell_values;\n"
"\n"
"TEvent* scriptapi_event_create(const char* name, double delay, double randomdelay, void (*handler)(TEvent*, TDynamicObject*));\n"
"TEvent* scriptapi_event_find(const char* name);\n"
"const char* scriptapi_event_getname(TEvent *e);\n"
"void scriptapi_event_dispatch(TEvent *e, TDynamicObject *activator, double delay);\n"
"\n"
"TTrack* scriptapi_track_find(const char* name);\n"
"bool scriptapi_track_isoccupied(TTrack *track);\n"
"\n"
"TIsolated* scriptapi_isolated_find(const char* name);\n"
"bool scriptapi_isolated_isoccupied(TIsolated *isolated);\n"
"\n"
"const char* scriptapi_train_getname(TDynamicObject *dyn);\n"
"void scriptapi_dynobj_putvalues(TDynamicObject *dyn, const char *str, double num1, double num2);\n"
"\n"
"TMemCell* scriptapi_memcell_find(const char *name);\n"
"memcell_values scriptapi_memcell_read(TMemCell *mc);\n"
"void scriptapi_memcell_update(TMemCell *mc, const char *str, double num1, double num2);\n"
"\n"
"double scriptapi_random(double a, double b);\n"
"void scriptapi_writelog(const char* txt);\n"
"]]\n"
"\n"
"local ns = ffi.C\n"
"\n"
"local module = {}\n"
"\n"
"module.event_create = ns.scriptapi_event_create\n"
"function module.event_preparefunc(f)\n"
"    return ffi.cast(\"void (*)(TEvent*, TDynamicObject*)\", f)\n"
"end\n"
"module.event_find = ns.scriptapi_event_find\n"
"function module.event_getname(a)\n"
"    return ffi.string(ns.scriptapi_event_getname(a))\n"
"end\n"
"module.event_dispatch = ns.scriptapi_event_dispatch\n"
"function module.event_dispatch_n(a, b, c)\n"
"    ns.scriptapi_event_dispatch(ns.scriptapi_event_find(a), b, c)\n"
"end\n"
"\n"
"module.track_find = ns.scriptapi_track_find\n"
"module.track_isoccupied = ns.scriptapi_track_isoccupied\n"
"function module.track_isoccupied_n(a)\n"
"    return ns.scriptapi_track_isoccupied(ns.scriptapi_track_find(a))\n"
"end\n"
"\n"
"module.isolated_find = ns.scriptapi_isolated_find\n"
"module.isolated_isoccupied = ns.scriptapi_isolated_isoccupied\n"
"function module.isolated_isoccupied_n(a)\n"
"    return ns.scriptapi_isolated_isoccupied(ns.scriptapi_isolated_find(a))\n"
"end\n"
"\n"
"function module.train_getname(a)\n"
"    return ffi.string(ns.scriptapi_train_getname(a))\n"
"end\n"
"function module.dynobj_putvalues(a, b)\n"
"    ns.scriptapi_dynobj_putvalues(a, b.str, b.num1, b.num2)\n"
"end\n"
"\n"
"module.memcell_find = ns.scriptapi_memcell_find\n"
"function module.memcell_read(a)\n"
"    native = ns.scriptapi_memcell_read(a)\n"
"    mc = { }\n"
"    mc.str = ffi.string(native.str)\n"
"    mc.num1 = native.num1\n"
"    mc.num2 = native.num2\n"
"    return mc\n"
"end\n"
"function module.memcell_read_n(a)\n"
"    return module.memcell_read(ns.scriptapi_memcell_find(a))\n"
"end\n"
"function module.memcell_update(a, b)\n"
"    ns.scriptapi_memcell_update(a, b.str, b.num1, b.num2)\n"
"end\n"
"function module.memcell_update_n(a, b)\n"
"    ns.scriptapi_memcell_update(ns.scriptapi_memcell_find(a), b.str, b.num1, b.num2)\n"
"end\n"
"\n"
"module.random = ns.scriptapi_random\n"
"module.writelog = ns.scriptapi_writelog\n"
"\nreturn module\n";
