int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE , LPTSTR lpstrCmdLine, int nCmdShow) { createGlobal(); FrameWindow mw; mw.CreateEx(); mw.ShowWindow(SW_MAXIMIZE); mw.UpdateWindow(); MSG m; ::ZeroMemory(&m, sizeof(m)); for (;;) { ::ZeroMemory(&m, sizeof(m)); if (::PeekMessage(&m, NULL, 0, 0, PM_NOREMOVE)) { ::GetMessage(&m, NULL, 0, 0); if (m.message == WM_QUIT) { break; } ::TranslateMessage(&m); ::DispatchMessage(&m); } else { mw.onIdle(); } } destroyGlobal(); return 0; }
//Initialize the javascript context and expose the methods in exposer bool _BeaScript::init() { lastError = ""; HandleScope handle_scope; if (globalTemplate.IsEmpty()){ globalTemplate = v8::Persistent<v8::ObjectTemplate>::New(createGlobal()); } //Create the context m_context = v8::Context::New(NULL, globalTemplate); Context::Scope context_scope(m_context); globalSandbox = v8::Persistent<v8::Object>::New(v8::Object::New()); Handle<Value> vCmdLine = bea::Convert<std::vector<std::string> >::ToJS(cmdLine); Handle<Object> objProcess = v8::Object::New(); objProcess->Set(v8::String::New("argv"), vCmdLine); m_context->Global()->Set(v8::String::New("process"), objProcess); expose(); executeScript("./loader.js"); CloneObject(m_context->Global(), globalSandbox); return true; }
bool JSAPITest::init() { rt = createRuntime(); if (!rt) return false; cx = createContext(); if (!cx) return false; JS_BeginRequest(cx); JS::RootedObject global(cx, createGlobal()); if (!global) return false; JS_EnterCompartment(cx, global); return true; }
bool JSAPITest::init() { rt = createRuntime(); if (!rt) return false; cx = createContext(); if (!cx) return false; #ifdef JS_GC_ZEAL JS_SetGCZeal(cx, 0, 0); #endif JS_BeginRequest(cx); js::RootedObject global(cx, createGlobal()); if (!global) return false; oldCompartment = JS_EnterCompartment(cx, global); return oldCompartment != NULL; }
/* function: createGlobal */ static int tolua_LuaAPI_createGlobal00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( !tolua_isnoobj(tolua_S,1,&tolua_err) ) goto tolua_lerror; else #endif { { createGlobal(); } } return 0; #ifndef TOLUA_RELEASE tolua_lerror: tolua_error(tolua_S,"#ferror in function 'createGlobal'.",&tolua_err); return 0; #endif }
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE , LPTSTR lpstrCmdLine, int nCmdShow) { createGlobal(); FrameWindow mw; mw.CreateEx(); mw.ShowWindow(SW_SHOWMAXIMIZED); mw.UpdateWindow(); MSG m; ::ZeroMemory(&m, sizeof(m)); float life = 0.0f; float frame = 0.0f; float fps = 0.0f; const size_t tDuration = 1000; const size_t tInterval = 1000/65; float inter = tInterval; for (;;) { ::ZeroMemory(&m, sizeof(m)); if (::PeekMessage(&m, NULL, 0, 0, PM_NOREMOVE)) { ::GetMessage(&m, NULL, 0, 0); if (m.message == WM_QUIT) { break; } ::TranslateMessage(&m); ::DispatchMessage(&m); } else { // GetTickCount only has a guaranteed resolution of 1/18th of a second, which is pretty horrible for game timing //Retrieves the number of milliseconds that have elapsed since the system was started, up to 49.7 days. float beforeRun = ::timeGetTime(); mw.onIdle(inter); float afterRun = ::timeGetTime(); float timeRun = afterRun - beforeRun; if (timeRun > tInterval) { inter = timeRun; } else { inter = tInterval; } ++frame; float timeSleep = tInterval - timeRun; //¼ÆËãFPS life += inter; if (life >= tDuration) { fps = 1000.0f * frame / life; mw.setFPS(fps); life = 0.0f; frame = 0.0f; } //ÏÞÖ¡ while(timeSleep >= 1.0f) { Sleep(1); --timeSleep; } } } destroyGlobal(); return 0; }