LOCAL TBOOL fb_init(WINDISPLAY *mod, TTAGITEM *tags) { struct TExecBase *TExecBase = TGetExecBase(mod); // mod->fbd_OpenTags = tags; for (;;) { TTAGITEM tags[2]; tags[0].tti_Tag = TTask_UserData; tags[0].tti_Value = (TTAG) mod; tags[1].tti_Tag = TTAG_DONE; mod->fbd_Task = TCreateTask(&mod->fbd_Module.tmd_Handle.thn_Hook, tags); if (mod->fbd_Task == TNULL) break; mod->fbd_CmdPort = TGetUserPort(mod->fbd_Task); mod->fbd_CmdPortSignal = TGetPortSignal(mod->fbd_CmdPort); return TTRUE; } fb_exit(mod); return TFALSE; }
LOCAL void fb_openwindow(WINDISPLAY *mod, struct TVRequest *req) { struct TExecBase *TExecBase = TGetExecBase(mod); TTAGITEM tags[2]; struct THook taskhook; tags[0].tti_Tag = TTask_UserData; tags[0].tti_Value = (TTAG) req; tags[1].tti_Tag = TTAG_DONE; TInitHook(&taskhook, fb_window_dispatch, TNULL); TCreateTask(&taskhook, tags); }
static TBOOL rfb_init(RFBDISPLAY *mod, TTAGITEM *tags) { TAPTR TExecBase = TGetExecBase(mod); mod->rfb_OpenTags = tags; for (;;) { TTAGITEM tags[2]; tags[0].tti_Tag = TTask_UserData; tags[0].tti_Value = (TTAG) mod; tags[1].tti_Tag = TTAG_DONE; mod->rfb_Task = TCreateTask(&mod->rfb_Module.tmd_Handle.thn_Hook, tags); if (mod->rfb_Task == TNULL) break; mod->rfb_CmdPort = TGetUserPort(mod->rfb_Task); return TTRUE; } rfb_exit(mod); return TFALSE; }
LOCAL TBOOL tek_lib_visual_io_open(TEKVisual *vis) { struct TExecBase *TExecBase = vis->vis_ExecBase; struct IOData *iodata = TAlloc(TNULL, sizeof(struct IOData)); if (iodata) { TTAGITEM tags[2]; sprintf(iodata->atomname, "msgport.ui.%p", TFindTask(TNULL)); iodata->vis = vis; vis->vis_IOData = iodata; tags[0].tti_Tag = TTask_UserData; tags[0].tti_Value = (TTAG) iodata; tags[1].tti_Tag = TTAG_DONE; struct THook taskhook; TInitHook(&taskhook, tek_lib_visual_io_dispatch, TNULL); vis->vis_IOTask = TCreateTask(&taskhook, tags); if (vis->vis_IOTask) return TTRUE; TFree(iodata); vis->vis_IOData = TNULL; } return TFALSE; }
static int tek_lib_exec_run(lua_State *L) { struct LuaExecTask *lexec = tek_lib_exec_check(L); struct TExecBase *TExecBase = lexec->exec; struct LuaExecChild *ctx; const char *fname = TNULL; const char *chunk = TNULL; const char *taskname = TNULL; size_t extralen = 0; struct THook hook; TTAGITEM tags[2]; int nremove = 1; TBOOL abort = TTRUE; for (;;) { if (lua_istable(L, 1)) { lua_getfield(L, 1, "abort"); if (lua_isboolean(L, -1)) abort = lua_toboolean(L, -1); lua_pop(L, 1); lua_getfield(L, 1, "taskname"); taskname = lua_tostring(L, -1); nremove = 2; lua_getfield(L, 1, "func"); if (!lua_isnoneornil(L, -1)) break; lua_pop(L, 1); lua_getfield(L, 1, "filename"); if (!lua_isnoneornil(L, -1)) break; lua_pop(L, 1); lua_getfield(L, 1, "chunk"); if (!lua_isnoneornil(L, -1)) { chunk = luaL_checklstring(L, -1, &extralen); break; } luaL_error(L, "required argument missing"); } lua_pushvalue(L, 1); break; } if (!chunk) { if (lua_type(L, -1) == LUA_TSTRING) fname = luaL_checklstring(L, -1, &extralen); else if (lua_isfunction(L, -1) && !lua_iscfunction(L, -1)) chunk = tek_lib_exec_dump(L, &extralen); else luaL_error(L, "not a Lua function, filename or table"); } ctx = lua_newuserdata(L, sizeof(struct LuaExecChild) + extralen + 1); memset(ctx, 0, sizeof *ctx); ctx->exec = lexec->exec; ctx->parent = lexec; ctx->taskname = tek_lib_exec_taskname(ctx->atomname, taskname); ctx->abort = abort; if (fname) { ctx->fname = (char *) (ctx + 1); strcpy(ctx->fname, (char *) fname); } else if (chunk) { memcpy(ctx + 1, chunk, extralen); ctx->chunklen = extralen; } /* remove arguments under userdata */ while (nremove--) lua_remove(L, -2); ctx->numargs = lua_gettop(L) - 2; /* push arg[0] on the stack, will be extraarg */ lua_getglobal(L, "arg"); if (lua_istable(L, -1)) { lua_rawgeti(L, -1, 0); lua_remove(L, -2); } if (lua_type(L, -1) != LUA_TSTRING) { lua_pop(L, 1); lua_pushnil(L); } ctx->args = tek_lib_exec_getargs(L, TExecBase, 2, ctx->numargs++, 1); lua_pop(L, 1); ctx->L = lua_newstate(tek_lib_exec_allocf, TExecBase); if (ctx->L == TNULL) { tek_lib_exec_freeargs(TExecBase, ctx->args, ctx->numargs); luaL_error(L, "cannot create interpreter"); } tags[0].tti_Tag = TTask_UserData; tags[0].tti_Value = (TTAG) ctx; tags[1].tti_Tag = TTAG_DONE; TInitHook(&hook, tek_lib_exec_run_dispatch, ctx); ctx->task = TCreateTask(&hook, tags); if (ctx->task == TNULL) { tek_lib_exec_freectxargs(ctx); lua_pop(L, 1); lua_pushnil(L); return 1; } lua_getfield(L, LUA_REGISTRYINDEX, TEK_LIB_TASK_CLASSNAME); lua_setmetatable(L, -2); lua_pushvalue(L, -1); ctx->ref = luaL_ref(L, lua_upvalueindex(2)); if (ctx->abort) tek_lib_exec_register_task_hook(L, TExecBase); return 1; }