// BOOL ViCbAddCtrl(HANDLE hCtrl, HANDLE hParent) SQInteger ViCbAddCtrl(HSQUIRRELVM v) { SQInteger nargs = sq_gettop(v); SQInteger hCtrl = 0; SQInteger hParent = 0; CContainerUI* pParentCtrl = NULL; CScriptMgr* pMgr = NULL; CPaintManagerUI* pPM = NULL; CControlUI* pCtrl = NULL; SQBool bRet = FALSE; if (!v || 2 + 1 != nargs) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 2)) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 3)) {goto _Exit_;} sq_getinteger(v, 2, &hCtrl); sq_getinteger(v, 3, &hParent); pCtrl = QiHwHandleToCtrl(hCtrl); pParentCtrl = (CContainerUI*)QiHwHandleToCtrl(hParent); if (!pCtrl) {goto _Exit_;} if (NULL == pParentCtrl) { pMgr = (CScriptMgr*)sq_getforeignptr(v); if (!pMgr) {goto _Exit_;} pPM = pMgr->GetManager(); if (!pPM) {goto _Exit_;} pParentCtrl = (CContainerUI*)pPM->GetRoot(); } if (!pParentCtrl || !pParentCtrl->IsContainer()) {goto _Exit_;} bRet = (SQBool)pParentCtrl->Add(pCtrl); _Exit_: sq_pushbool(v, bRet); return 1; }
// int VwGetPosHight(VApiHandle hWnd) SQInteger VwGetPosHight(HSQUIRRELVM v) { SQInteger nargs = sq_gettop(v); SQInteger nWnd = 0; WinMgrItem* pWin = NULL; HWND hWnd = NULL; SQInteger nRet = 0; RECT rc = {0}; if (!v || 1 + 1 != nargs) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 2)) {goto _Exit_;} sq_getinteger(v, 2, &nWnd); if (-1 == nWnd) { CScriptMgr* pMgr = (CScriptMgr*)sq_getforeignptr(v); if (!pMgr) {goto _Exit_;} CPaintManagerUI* pPM = pMgr->GetManager(); if (!pPM) {goto _Exit_;} hWnd = pPM->GetPaintWindow(); } else { hWnd = QiHwHandleToWin(nWnd)->pWinObj->GetHWND(); } ::GetWindowRect(hWnd, &rc); nRet = rc.bottom - rc.top; _Exit_: sq_pushinteger(v, nRet); return 1; }
// void VwUpdateLayout(HWND hWnd) SQInteger VwUpdateLayout(HSQUIRRELVM v) { SQInteger nargs = sq_gettop(v); SQInteger nWnd = 0; HWND hWnd = NULL; CPaintManagerUI* pPM = NULL; if (!v || 1 + 1 != nargs) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 2)) {goto _Exit_;} sq_getinteger(v, 2, &nWnd); if (-1 == nWnd) { CScriptMgr* pMgr = (CScriptMgr*)sq_getforeignptr(v); if (!pMgr) {goto _Exit_;} pPM = pMgr->GetManager(); if (!pPM) {goto _Exit_;} } else { pPM = QiHwHandleToWin(nWnd)->pWinObj->GetPM(); if (!pPM) {goto _Exit_;} } pPM->UpdateLayout(); _Exit_: return 1; }
// 脚本调用原型: // VApiHandle VApiHwFindControl(HANDLE hWnd, string CtrlName); SQInteger ViHwFindControl(HSQUIRRELVM v) { VApiHandle hRet = 0; const SQChar* szCtrlName = NULL; SQInteger nargs = sq_gettop(v); SQInteger nWnd = 0; HANDLE hWnd = NULL; CScriptMgr* pMgr = NULL; CPaintManagerUI* pPM = NULL; if (!v || 2 + 1 != nargs) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 2)) {goto _Exit_;} if (OT_STRING != sq_gettype(v, 3)) {goto _Exit_;} sq_getinteger(v, 2, &nWnd); sq_getstring(v, 3, &szCtrlName); if (-1 == nWnd) { pMgr = (CScriptMgr*)sq_getforeignptr(v); if (!pMgr) {goto _Exit_;} pPM = pMgr->GetManager(); } else { pPM = QiHwHandleToWin(nWnd)->pWinObj->GetPM(); } if (!pPM) {goto _Exit_;} // fixbug - 未验证pm合法性 hRet = QiHwCtrlToHandle(pPM->FindControl(szCtrlName)); _Exit_: sq_pushinteger(v, hRet); return 1; }
// void VwSetWindowPos(HWND hWnd, HWND hWndlnsertAfter,int X, int Y, int cx, int cy, UNIT Flags) SQInteger VwSetWindowPos(HSQUIRRELVM v) { SQInteger uIDEvent = 0; SQInteger nargs = sq_gettop(v); SQInteger nWnd = 0; SQInteger nWndlnsertAfter = NULL; HWND hWnd = NULL; HWND hWndlnsertAfter = NULL; int X = 0; int Y = 0; int cx = 0; int cy = 0; UINT uFlags = 0; if (!v || 7 + 1 != nargs) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 2)) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 3)) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 4) && OT_FLOAT != sq_gettype(v, 4)) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 5) && OT_FLOAT != sq_gettype(v, 5)) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 6) && OT_FLOAT != sq_gettype(v, 6)) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 7) && OT_FLOAT != sq_gettype(v, 7)) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 8)) {goto _Exit_;} sq_getinteger(v, 2, &nWnd); sq_getinteger(v, 3, &nWndlnsertAfter); sq_getinteger(v, 4, &X); sq_getinteger(v, 5, &Y); sq_getinteger(v, 6, &cx); sq_getinteger(v, 7, &cy); sq_getinteger(v, 8, (SQInteger*)&uFlags); if (-1 == nWnd) { CScriptMgr* pMgr = (CScriptMgr*)sq_getforeignptr(v); if (!pMgr) {goto _Exit_;} CPaintManagerUI* pPM = pMgr->GetManager(); if (!pPM) {goto _Exit_;} hWnd = pPM->GetPaintWindow(); } else { hWnd = QiHwHandleToWin(nWnd)->pWinObj->GetHWND(); } if (HWND_TOP == (HWND)nWndlnsertAfter || HWND_BOTTOM == (HWND)nWndlnsertAfter || HWND_TOPMOST == (HWND)nWndlnsertAfter || HWND_TOPMOST == (HWND)nWndlnsertAfter) { hWndlnsertAfter = (HWND)nWndlnsertAfter; } else { hWndlnsertAfter = QiHwHandleToWin(nWndlnsertAfter)->pWinObj->GetHWND(); } ::SetWindowPos(hWnd, hWndlnsertAfter, X, Y, cx, cy, uFlags); //::MoveWindow( hWnd, X, Y, cx, cy, TRUE); _Exit_: return 0; }
extern "C" void squirrel_print_helper(HSQUIRRELVM vm, const SQChar *format, ...) { SQChar buffer[4096]; struct rust_data *ptr; va_list va; ptr = ((struct rust_data *)sq_getforeignptr(vm)); if (!ptr || !ptr->print_callback) return; va_start(va, format); scvsprintf(buffer, 4096, format, va); va_end(va); return ptr->print_callback(ptr, buffer); }
void Squirrel::CompileError(HSQUIRRELVM vm, const SQChar *desc, const SQChar *source, SQInteger line, SQInteger column) { SQChar buf[1024]; seprintf(buf, lastof(buf), "Error %s:" OTTD_PRINTF64 "/" OTTD_PRINTF64 ": %s", source, line, column, desc); /* Check if we have a custom print function */ Squirrel *engine = (Squirrel *)sq_getforeignptr(vm); engine->crashed = true; SQPrintFunc *func = engine->print_func; if (func == NULL) { DEBUG(misc, 0, "[Squirrel] Compile error: %s", buf); } else { (*func)(true, buf); } }
void Squirrel::ErrorPrintFunc(HSQUIRRELVM vm, const SQChar *s, ...) { va_list arglist; SQChar buf[1024]; va_start(arglist, s); scvsnprintf(buf, lengthof(buf), s, arglist); va_end(arglist); /* Check if we have a custom print function */ SQPrintFunc *func = ((Squirrel *)sq_getforeignptr(vm))->print_func; if (func == NULL) { scfprintf(stderr, _SC("%s"), buf); } else { (*func)(true, buf); } }
void Squirrel::PrintFunc(HSQUIRRELVM vm, const SQChar *s, ...) { va_list arglist; SQChar buf[1024]; va_start(arglist, s); vseprintf(buf, lastof(buf) - 2, s, arglist); va_end(arglist); strecat(buf, "\n", lastof(buf)); /* Check if we have a custom print function */ SQPrintFunc *func = ((Squirrel *)sq_getforeignptr(vm))->print_func; if (func == NULL) { printf("%s", buf); } else { (*func)(false, buf); } }
void Squirrel::CompileError(HSQUIRRELVM vm, const SQChar *desc, const SQChar *source, SQInteger line, SQInteger column) { SQChar buf[1024]; #ifdef _SQ64 scsnprintf(buf, lengthof(buf), _SC("Error %s:%ld/%ld: %s"), source, line, column, desc); #else scsnprintf(buf, lengthof(buf), _SC("Error %s:%d/%d: %s"), source, line, column, desc); #endif /* Check if we have a custom print function */ Squirrel *engine = (Squirrel *)sq_getforeignptr(vm); engine->crashed = true; SQPrintFunc *func = engine->print_func; if (func == NULL) { scfprintf(stderr, _SC("%s"), buf); } else { (*func)(true, buf); } }
// HANDLE VwSnapShot(VApiHandle hWnd) SQInteger VwSnapShot(HSQUIRRELVM v) { SQInteger nargs = sq_gettop(v); SQInteger nWnd = 0; HWND hWnd = NULL; CUIImage* pImg = NULL; CScriptMgr* pMgr = NULL; CPaintManagerUI* pPM = NULL; BOOL bIsAlphaWin = NULL; VApiHandle hRet = NULL; CUIRect rt; if (!v || 1 + 1 != nargs) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 2)) {goto _Exit_;} sq_getinteger(v, 2, &nWnd); if (-1 == nWnd) { pMgr = (CScriptMgr*)sq_getforeignptr(v); if (!pMgr) {goto _Exit_;} pPM = pMgr->GetManager(); if (!pPM) {goto _Exit_;} hWnd = pPM->GetPaintWindow(); } else { hWnd = QiHwHandleToWin(nWnd)->pWinObj->GetHWND(); } ::GetWindowRect(hWnd, &rt); bIsAlphaWin = pPM->IsAlphaWin(); pImg = new CUIImage(); pImg->Create(pPM->GetPaintDC(), rt.GetWidth(), rt.GetHeight(), 0, TRUE); ::PrintWindow(hWnd, pImg->GetDC(), 0); ::SendMessage(hWnd, WM_PRINT, (WPARAM)pImg->GetDC(), PRF_NONCLIENT | PRF_CLIENT | PRF_ERASEBKGND | PRF_CHILDREN); hRet = QiHwObjToHandle(pImg); _Exit_: sq_pushinteger(v, hRet); return 1; }
//BOOL VwSetLayeredWindowAttributes(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags); SQInteger VwSetLayeredWindowAttributes(HSQUIRRELVM v) { SQInteger uIDEvent = 0; SQInteger nargs = sq_gettop(v); SQInteger nWnd = 0; HWND hWnd = NULL; COLORREF crKey = 0; int bAlpha = 0; DWORD dwFlags = 0; if (!v || 4 + 1 != nargs) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 2)) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 3)) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 4)) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 5)) {goto _Exit_;} sq_getinteger(v, 2, &nWnd); sq_getinteger(v, 3, (SQInteger*)&crKey); sq_getinteger(v, 4, (SQInteger*)&bAlpha); sq_getinteger(v, 5, (SQInteger*)&dwFlags); if (-1 == nWnd) { CScriptMgr* pMgr = (CScriptMgr*)sq_getforeignptr(v); if (!pMgr) {goto _Exit_;} CPaintManagerUI* pPM = pMgr->GetManager(); if (!pPM) {goto _Exit_;} hWnd = pPM->GetPaintWindow(); } else { hWnd = QiHwHandleToWin(nWnd)->pWinObj->GetHWND(); } //::SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) ^ WS_EX_LAYERED); ::SetLayeredWindowAttributes(hWnd, crKey, (BYTE)bAlpha, dwFlags); ::RedrawWindow(hWnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN); _Exit_: return 1; }
void Squirrel::RunError(HSQUIRRELVM vm, const SQChar *error) { /* Set the print function to something that prints to stderr */ SQPRINTFUNCTION pf = sq_getprintfunc(vm); sq_setprintfunc(vm, &Squirrel::ErrorPrintFunc); /* Check if we have a custom print function */ SQChar buf[1024]; scsnprintf(buf, lengthof(buf), _SC("Your script made an error: %s\n"), error); Squirrel *engine = (Squirrel *)sq_getforeignptr(vm); SQPrintFunc *func = engine->print_func; if (func == NULL) { scfprintf(stderr, _SC("%s"), buf); } else { (*func)(true, buf); } /* Print below the error the stack, so the users knows what is happening */ sqstd_printcallstack(vm); /* Reset the old print function */ sq_setprintfunc(vm, pf); }
// BOOL VwKillTimer(SQInteger uIDEvent) SQInteger VwKillTimer(HSQUIRRELVM v) { SQUserPointer uIDEvent = 0; SQInteger nargs = sq_gettop(v); if (!v || 1 + 1 != nargs) {goto _Exit_;} if (OT_USERPOINTER != sq_gettype(v, 2)) {goto _Exit_;} sq_getuserpointer(v, 2, &uIDEvent); CScriptMgr* pMgr = (CScriptMgr*)sq_getforeignptr(v); if (!pMgr) {goto _Exit_;} CPaintManagerUI* pPM = pMgr->GetManager(); if (!pPM) {goto _Exit_;} ::KillTimer(pPM->GetPaintWindow(), (UINT_PTR)uIDEvent); delete (SetTimerParam*)uIDEvent; _Exit_: sq_pushbool(v, TRUE); return 1; }
SQInteger _VwSetTimerInternal(HSQUIRRELVM v, TIMERPROC lpTimerFunc) { SQInteger nargs = sq_gettop(v); SQInteger Handle = 0; SQInteger uElapse = 0; LPCTSTR pstrFunc = NULL; SetTimerParam* pTimerParam = NULL; SQUserPointer nRet = NULL; if (!v || 3 + 1 != nargs) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 2)) {goto _Exit_;} if (OT_STRING != sq_gettype(v, 3)) {goto _Exit_;} if (OT_INSTANCE != sq_gettype(v, 4)) {goto _Exit_;} sq_getinteger(v, 2, &uElapse); sq_getstring(v, 3, &pstrFunc); pTimerParam = new SetTimerParam(); pTimerParam->v = v; pTimerParam->sFunc = pstrFunc; sq_getstackobj(v, 4, &pTimerParam->Obj); CScriptMgr* pMgr = (CScriptMgr*)sq_getforeignptr(v); if (!pMgr) {goto _Exit_;} CPaintManagerUI* pPM = pMgr->GetManager(); if (!pPM) {goto _Exit_;} if (NULL != ::SetTimer(pPM->GetPaintWindow(), (UINT_PTR)pTimerParam, uElapse, lpTimerFunc)) { nRet = (SQUserPointer)pTimerParam; } else { nRet = NULL; } _Exit_: sq_pushuserpointer(v, nRet); return 1; }
static SQInteger ngx_squ_tcp_request_recv(HSQUIRRELVM v) { char *errstr; size_t size; SQRESULT rc; ngx_buf_t *b; ngx_connection_t *c; ngx_squ_thread_t *thr; ngx_squ_tcp_ctx_t *ctx; ngx_tcp_session_t *s; thr = sq_getforeignptr(v); ngx_log_debug0(NGX_LOG_DEBUG_CORE, thr->log, 0, "squ tcp request recv"); ctx = thr->module_ctx; s = ctx->s; c = s->connection; /* TODO: the arguments in squ stack */ rc = sq_getinteger(v, 2, (SQInteger *) &size); b = s->buffer; if (b == NULL || (size_t) (b->end - b->start) < size) { if (b != NULL && (size_t) (b->end - b->start) > c->pool->max) { ngx_pfree(c->pool, b->start); } size = ngx_max(ngx_pagesize, size); b = ngx_create_temp_buf(c->pool, size); if (b == NULL) { errstr = "ngx_create_temp_buf() failed"; goto error; } s->buffer = b; } b->last = b->pos; c->read->handler = ngx_squ_tcp_request_read_handler; c->write->handler = ngx_squ_tcp_request_dummy_handler; ctx->rc = 0; ctx->not_event = 1; ngx_squ_tcp_request_read_handler(c->read); ctx->not_event = 0; if (ctx->rc != NGX_AGAIN) { return ctx->rc; } return sq_suspendvm(v); error: sq_pushbool(v, SQFalse); #if 0 sq_pushstring(, (SQChar *) errstr, -1); #endif return 1; }
inline ScriptEngine* getEngine(HSQUIRRELVM vm) { return static_cast<ScriptEngine*>(sq_getforeignptr(vm)); }
Context* Context::Detail::getContext(HSQUIRRELVM vm) { return static_cast<Context*>(sq_getforeignptr(vm)); }
/** * Get the pointer as set by SetGlobalPointer. */ static void *GetGlobalPointer(HSQUIRRELVM vm) { return ((Squirrel *)sq_getforeignptr(vm))->global_pointer; }
// HANDLE VwCreateWin( // VApiHandle hWndParent, int X, int Y, int nWidth, int nHeight, // WCHAR* wszRegName, WCHAR* wszNewName, BOOL bIsAlpha) SQInteger VwCreateWin(HSQUIRRELVM v) { SQInteger nargs = sq_gettop(v); SQInteger nWndParent = 0; HWND hWndParent = NULL; CUIImage* pImg = NULL; CScriptMgr* pMgr = NULL; CPaintManagerUI* pPM = NULL; int X = 0; int Y = 0; int nWidth = 0; int nHeight = 0; const SQChar* pwszRegName = NULL; const SQChar* pwszNewName = NULL; WCHAR wszNewName[60] = {0}; SQBool bIsAlphaWin = NULL; WinMgrItem* pWinMgrIt = NULL; HWND hWnd = NULL; CWindowWnd* pWinObj = NULL; SQInteger nRet = 0; CMarkupNode* pRootXm = NULL; if (!v || 8 + 1 != nargs) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 2)) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 3)) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 4)) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 5)) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 6)) {goto _Exit_;} if (OT_STRING != sq_gettype(v, 7)) {goto _Exit_;} if (OT_STRING != sq_gettype(v, 8)) {goto _Exit_;} if (OT_BOOL != sq_gettype(v, 9)) {goto _Exit_;} sq_getinteger(v, 2, &nWndParent); sq_getinteger(v, 3, &X); sq_getinteger(v, 4, &Y); sq_getinteger(v, 5, &nWidth); sq_getinteger(v, 6, &nHeight); sq_getstring(v, 7, &pwszRegName); //sq_getinteger(v, 8, &wszNewName); sq_getbool(v, 9, &bIsAlphaWin); swprintf_s(wszNewName, 60, L"%x", ::GetTickCount()); if (nWndParent) { hWndParent = QiHwHandleToWin(nWndParent)->pWinObj->GetHWND(); } pMgr = (CScriptMgr*)sq_getforeignptr(v); if (!pMgr) {goto _Exit_;} pPM = pMgr->GetManager(); if (!pPM || !pPM->GetWinMgr()) {goto _Exit_;} pWinMgrIt = pPM->GetWinMgr()->FindWinByName(pwszRegName); if (!pWinMgrIt) {goto _Exit_;} // 新建立个模板,因为需要可重复用以前的名字 pRootXm = new CMarkupNode(*pWinMgrIt->pWinXML); pWinObj = new CWindowTemplate(pWinMgrIt->pWinObj); pWinObj->GetPM()->SetWinMgr(pPM->GetWinMgr()); pWinObj->SetDefaultResource(pRootXm); pWinMgrIt = pPM->GetWinMgr()->AddOneWin(pWinObj, wszNewName, pRootXm, X, Y, nWidth, nHeight, pWinMgrIt->dwStyle, pWinMgrIt->dwExStyle, &pWinMgrIt->ExInfo); if (!bIsAlphaWin) { hWnd = pWinObj->Create(hWndParent, pwszNewName, pWinMgrIt->dwStyle, pWinMgrIt->dwExStyle, X, Y, nWidth, nHeight, 0); } else { hWnd = pWinObj->CreateAlphaWin(hWndParent, pwszNewName, pWinMgrIt->dwStyle | WS_EX_LAYERED, pWinMgrIt->dwExStyle, X, Y, nWidth, nHeight); } if (!hWnd) {goto _Exit_;} nRet = QiHwObjToHandle(pWinMgrIt); _Exit_: sq_pushinteger(v, nRet); return 1; }
/* static */ bool Squirrel::CreateClassInstanceVM(HSQUIRRELVM vm, const char *class_name, void *real_instance, HSQOBJECT *instance, SQRELEASEHOOK release_hook, bool prepend_API_name) { Squirrel *engine = (Squirrel *)sq_getforeignptr(vm); int oldtop = sq_gettop(vm); /* First, find the class */ sq_pushroottable(vm); if (prepend_API_name) { size_t len = strlen(class_name) + strlen(engine->GetAPIName()) + 1; char *class_name2 = (char *)alloca(len); seprintf(class_name2, class_name2 + len - 1, "%s%s", engine->GetAPIName(), class_name); sq_pushstring(vm, class_name2, -1); } else { sq_pushstring(vm, class_name, -1); } if (SQ_FAILED(sq_get(vm, -2))) { DEBUG(misc, 0, "[squirrel] Failed to find class by the name '%s%s'", prepend_API_name ? engine->GetAPIName() : "", class_name); sq_settop(vm, oldtop); return false; } /* Create the instance */ if (SQ_FAILED(sq_createinstance(vm, -1))) { DEBUG(misc, 0, "[squirrel] Failed to create instance for class '%s%s'", prepend_API_name ? engine->GetAPIName() : "", class_name); sq_settop(vm, oldtop); return false; } if (instance != NULL) { /* Find our instance */ sq_getstackobj(vm, -1, instance); /* Add a reference to it, so it survives for ever */ sq_addref(vm, instance); } sq_remove(vm, -2); // Class-name sq_remove(vm, -2); // Root-table /* Store it in the class */ sq_setinstanceup(vm, -1, real_instance); if (release_hook != NULL) sq_setreleasehook(vm, -1, release_hook); if (instance != NULL) sq_settop(vm, oldtop); return true; }