1 /* 2 * Copyright 2003-2020, Björn Ståhl 3 * License: 3-Clause BSD, see COPYING file in arcan source repository. 4 * Reference: http://arcan-fe.com 5 */ 6 7 #ifndef _HAVE_ARCAN_LUA 8 #define _HAVE_ARCAN_LUA 9 10 #define LUAAPI_VERSION_MAJOR 0 11 #define LUAAPI_VERSION_MINOR 12 12 13 /* arcan_luactx* is just an intermediary alias for lua_State */ 14 struct arcan_luactx; 15 struct luaL_Reg; 16 17 enum { 18 ARCAN_LUA_SWITCH_APPL = 1, 19 ARCAN_LUA_SWITCH_APPL_NOADOPT = 2, 20 ARCAN_LUA_RECOVERY_SWITCH = 3, 21 ARCAN_LUA_RECOVERY_FATAL_IGNORE = 4 22 }; 23 24 typedef struct luaL_Reg* (*module_init_prototype)(int, int, int); 25 26 /* we separate alloc and mapfunctions to allow partial VM execution 27 * BEFORE we have exposed the engine functions. This allows "constants" 28 * to be calculated while still enforcing the themename() entrypoint */ 29 struct arcan_luactx* arcan_lua_alloc(); 30 31 void arcan_lua_mapfunctions( 32 struct arcan_luactx* dst, int debuglevel); 33 34 char* arcan_lua_main(struct arcan_luactx*, const char* input, bool file_in); 35 void arcan_lua_dostring(struct arcan_luactx*, const char* sbuf, const char* name); 36 37 /* cbdrop is part of crash recovery and sweeps all context stacks looking 38 * for vobjects with tags that reference any lua context (hence not multi- 39 * context safe as is) */ 40 void arcan_lua_cbdrop(); 41 void arcan_lua_shutdown(struct arcan_luactx*); 42 void arcan_lua_tick(struct arcan_luactx*, size_t, size_t); 43 44 /* access the last known crash source, used when a [callvoidfun] has 45 * failed and longjumped into the set jump buffer */ 46 const char* arcan_lua_crash_source(struct arcan_luactx*); 47 48 /* for initialization, update / push all the global constants used */ 49 void arcan_lua_pushglobalconsts(struct arcan_luactx* ctx); 50 51 void arcan_lua_setglobalint(struct arcan_luactx* ctx, const char* key, int val); 52 void arcan_lua_setglobalstr(struct arcan_luactx* ctx, 53 const char* key, const char* val); 54 55 /* Forward an event to the related script defined entry point. Returns true 56 * if the event was consumed (default) or false when the engine is in a vid 57 * blocking state OR (event not input / no input_raw handler). 58 * 59 * If [ev] is empty it is used as a marker for a completed buffer flush. */ 60 bool arcan_lua_pushevent(struct arcan_luactx* ctx, arcan_event* ev); 61 62 /* Run the entry-point named [fun], the applname specific prefix will be 63 * added internally. Any elements in argv will be added as an integer 64 * indexed table and supplied as the argument. Returns false if no such 65 * function is defined in the VM state. 66 */ 67 bool arcan_lua_callvoidfun(struct arcan_luactx* ctx, 68 const char* fun, bool warn, const char** argv); 69 70 /* serialize a Lua- parseable snapshot of the various mapped subsystems and 71 * resources into the (dst) filestream. If delim is set, we're in streaming 72 * mode so a delimiter will be added to account for more snapshots over the 73 * same stream */ 74 void arcan_lua_statesnap(FILE* dst, const char* tag, bool delim); 75 76 /* 77 * will sweep the main rendertarget in the active context and expose running 78 * frameserver connections through an applname_adopt handler indended as a 79 * continuation of recoveryexternal 80 */ 81 void arcan_lua_adopt(struct arcan_luactx* ctx); 82 83 /* nonblock/read from (dst) filestream until an #ENDBLOCK\n tag is encountered, 84 * parse this and push it into the struct arcan_luactx as the first 85 * and only argument to the function pointed out with (dstfun). */ 86 void arcan_lua_stategrab(struct arcan_luactx* ctx, char* dstfun, int fd); 87 88 /* 89 * create a new external listening endpoint and expose via the _adopt handler, 90 * the purpose is to expose a pre-existing connection via _stdin. 91 */ 92 bool arcan_lua_launch_cp( 93 struct arcan_luactx*, const char* connp, const char* key); 94 95 #ifdef ARCAN_LWA 96 struct subseg_output; 97 bool platform_lwa_targetevent(struct subseg_output*, arcan_event* ev); 98 bool platform_lwa_allocbind_feed( 99 struct arcan_luactx* ctx, arcan_vobj_id rtgt, enum ARCAN_SEGID type, uintptr_t cbtag); 100 void arcan_lwa_subseg_ev( 101 struct arcan_luactx* ctx, arcan_vobj_id src, uintptr_t cb_tag, arcan_event* ev); 102 #endif 103 104 #ifdef LUA_PRIVATE 105 enum arcan_ffunc_rv arcan_lua_proctarget FFUNC_HEAD; 106 #endif 107 108 #endif 109 110