static VALUE pkcs11_C_GetSlotList(VALUE self, VALUE presented) { CK_ULONG ulSlotCount; CK_SLOT_ID_PTR pSlotList; CK_RV rv; CK_C_GetSlotList func; CK_ULONG i; VALUE ary = rb_ary_new(); GetFunction(self, C_GetSlotList, func); CallFunction(C_GetSlotList, func, rv, CK_FALSE, NULL_PTR, &ulSlotCount); if (rv != CKR_OK) pkcs11_raise(self,rv); pSlotList = (CK_SLOT_ID_PTR)malloc(ulSlotCount*sizeof(CK_SLOT_ID)); CallFunction(C_GetSlotList, func, rv, RTEST(presented) ? CK_TRUE : CK_FALSE, pSlotList, &ulSlotCount); if (rv != CKR_OK) { free(pSlotList); pkcs11_raise(self,rv); } for (i = 0; i < ulSlotCount; i++) rb_ary_push(ary, HANDLE2NUM(pSlotList[i])); free(pSlotList); return ary; }
static VALUE pkcs11_C_GetMechanismList(VALUE self, VALUE slot_id) { CK_RV rv; CK_C_GetMechanismList func; CK_MECHANISM_TYPE_PTR types; CK_ULONG count; VALUE ary; CK_ULONG i; ary = rb_ary_new(); GetFunction(self, C_GetMechanismList, func); CallFunction(C_GetMechanismList, func, rv, NUM2HANDLE(slot_id), NULL_PTR, &count); if (rv != CKR_OK) pkcs11_raise(self,rv); if (count == 0) return ary; types = (CK_MECHANISM_TYPE_PTR)malloc(sizeof(CK_MECHANISM_TYPE)*count); if (!types) rb_sys_fail(0); CallFunction(C_GetMechanismList, func, rv, NUM2HANDLE(slot_id), types, &count); if (rv != CKR_OK){ free(types); pkcs11_raise(self,rv); } for (i = 0; i < count; i++) rb_ary_push(ary, HANDLE2NUM(*(types+i))); free(types); return ary; }
double Cell_t::GetWidth(const XlfOper& ref) { // there is no get width function so we work it // out using the distances from far left double distRight(CallFunction(xlfGetCell, 44, ref, "Get Right Position").AsDouble()); double distLeft(CallFunction(xlfGetCell, 42, ref, "Get Left Position").AsDouble()); return distRight - distLeft; }
XlfOper Notes_t::GetNote(const XlfOper& cellRef, int startCharacter, int numChars) { if(numChars == 0) { return CallFunction(xlfGetNote, cellRef, startCharacter + 1, "Get Note"); } else { return CallFunction(xlfGetNote, cellRef, startCharacter + 1, numChars, "Get Note"); } }
bool cPlugin_NewLua::OnExecuteCommand(cPlayer * a_Player, const AStringVector & a_Split) { cCSLock Lock(m_CriticalSection); const char * FnName = GetHookFnName(cPluginManager::HOOK_EXECUTE_COMMAND); ASSERT(FnName != NULL); if (!PushFunction(FnName)) { return false; } tolua_pushusertype(m_LuaState, a_Player, "cPlayer"); // Push the split: lua_createtable(m_LuaState, a_Split.size(), 0); int newTable = lua_gettop(m_LuaState); int index = 1; std::vector<std::string>::const_iterator iter = a_Split.begin(), end = a_Split.end(); while(iter != end) { tolua_pushstring(m_LuaState, (*iter).c_str()); lua_rawseti(m_LuaState, newTable, index); ++iter; ++index; } if (!CallFunction(2, 1, FnName)) { return false; } bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0); lua_pop(m_LuaState, 1); return bRetVal; }
bool cPlugin_NewLua::OnChat(cPlayer * a_Player, AString & a_Message) { cCSLock Lock(m_CriticalSection); const char * FnName = GetHookFnName(cPluginManager::HOOK_CHAT); ASSERT(FnName != NULL); if (!PushFunction(FnName)) { return false; } tolua_pushusertype(m_LuaState, a_Player, "cPlayer"); tolua_pushstring (m_LuaState, a_Message.c_str()); if (!CallFunction(2, 2, FnName)) { return false; } bool bRetVal = (tolua_toboolean(m_LuaState, -2, 0) > 0); if (lua_isstring(m_LuaState, -1)) { a_Message = tolua_tostring(m_LuaState, -1, ""); } lua_pop(m_LuaState, 2); return bRetVal; }
bool cPlugin_NewLua::OnBlockToPickups(cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups) { cCSLock Lock(m_CriticalSection); const char * FnName = GetHookFnName(cPluginManager::HOOK_BLOCK_TO_PICKUPS); ASSERT(FnName != NULL); if (!PushFunction(FnName)) { return false; } tolua_pushusertype(m_LuaState, a_World, "cWorld"); tolua_pushusertype(m_LuaState, a_Digger, "cEntity"); tolua_pushnumber (m_LuaState, a_BlockX); tolua_pushnumber (m_LuaState, a_BlockY); tolua_pushnumber (m_LuaState, a_BlockZ); tolua_pushnumber (m_LuaState, a_BlockType); tolua_pushnumber (m_LuaState, a_BlockMeta); tolua_pushusertype(m_LuaState, &a_Pickups, "cItems"); if (!CallFunction(8, 1, FnName)) { return false; } bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0); lua_pop(m_LuaState, 1); return bRetVal; }
bool cPlugin_NewLua::OnWeatherChanging(cWorld & a_World, eWeather & a_NewWeather) { cCSLock Lock(m_CriticalSection); const char * FnName = GetHookFnName(cPluginManager::HOOK_WEATHER_CHANGED); ASSERT(FnName != NULL); if (!PushFunction(FnName)) { return false; } tolua_pushusertype(m_LuaState, &a_World, "cWorld"); tolua_pushnumber (m_LuaState, a_NewWeather); if (!CallFunction(2, 2, FnName)) { return false; } bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0); if (lua_isnumber(m_LuaState, -2)) { a_NewWeather = (eWeather)lua_tointeger(m_LuaState, -2); } lua_pop(m_LuaState, 1); return bRetVal; }
bool cPlugin_NewLua::OnUpdatedSign( cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player ) { cCSLock Lock(m_CriticalSection); const char * FnName = GetHookFnName(cPluginManager::HOOK_UPDATED_SIGN); ASSERT(FnName != NULL); if (!PushFunction(FnName)) { return false; } tolua_pushusertype(m_LuaState, (void *)a_World, "cWorld"); tolua_pushnumber (m_LuaState, a_BlockX); tolua_pushnumber (m_LuaState, a_BlockY); tolua_pushnumber (m_LuaState, a_BlockZ); tolua_pushstring (m_LuaState, a_Line1.c_str()); tolua_pushstring (m_LuaState, a_Line2.c_str()); tolua_pushstring (m_LuaState, a_Line3.c_str()); tolua_pushstring (m_LuaState, a_Line4.c_str()); tolua_pushusertype(m_LuaState, (void *)a_Player, "cPlayer"); if (!CallFunction(9, 1, FnName)) { return false; } bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0); lua_pop(m_LuaState, 1); return bRetVal; }
bool cPlugin_NewLua::OnPlayerLeftClick(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status) { cCSLock Lock(m_CriticalSection); const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_LEFT_CLICK); ASSERT(FnName != NULL); if (!PushFunction(FnName)) { return false; } tolua_pushusertype(m_LuaState, &a_Player, "cPlayer"); tolua_pushnumber (m_LuaState, a_BlockX); tolua_pushnumber (m_LuaState, a_BlockY); tolua_pushnumber (m_LuaState, a_BlockZ); tolua_pushnumber (m_LuaState, a_BlockFace); tolua_pushnumber (m_LuaState, a_Status); if (!CallFunction(6, 1, FnName)) { return false; } bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0); lua_pop(m_LuaState, 1); return bRetVal; }
bool cPlugin_NewLua::OnPlayerUsedBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { cCSLock Lock(m_CriticalSection); const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_USED_BLOCK); ASSERT(FnName != NULL); if (!PushFunction(FnName)) { return false; } tolua_pushusertype(m_LuaState, &a_Player, "cPlayer"); tolua_pushnumber (m_LuaState, a_BlockX); tolua_pushnumber (m_LuaState, a_BlockY); tolua_pushnumber (m_LuaState, a_BlockZ); tolua_pushnumber (m_LuaState, a_BlockFace); tolua_pushnumber (m_LuaState, a_CursorX); tolua_pushnumber (m_LuaState, a_CursorY); tolua_pushnumber (m_LuaState, a_CursorZ); tolua_pushnumber (m_LuaState, a_BlockType); tolua_pushnumber (m_LuaState, a_BlockMeta); if (!CallFunction(10, 1, FnName)) { return false; } bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0); lua_pop(m_LuaState, 1); return bRetVal; }
std::wstring ScriptInterface::ToString(jsval obj, bool pretty) { if (JSVAL_IS_VOID(obj)) return L"(void 0)"; // Try to stringify as JSON if possible // (TODO: this is maybe a bad idea since it'll drop 'undefined' values silently) if (pretty) { StringifierW str; // Temporary disable the error reporter, so we don't print complaints about cyclic values JSErrorReporter er = JS_SetErrorReporter(m->m_cx, NULL); bool ok = JS_Stringify(m->m_cx, &obj, NULL, INT_TO_JSVAL(2), &StringifierW::callback, &str) == JS_TRUE; // Restore error reporter JS_SetErrorReporter(m->m_cx, er); if (ok) return str.stream.str(); // Clear the exception set when Stringify failed JS_ClearPendingException(m->m_cx); } // Caller didn't want pretty output, or JSON conversion failed (e.g. due to cycles), // so fall back to obj.toSource() std::wstring source = L"(error)"; CallFunction(obj, "toSource", source); return source; }
/* * Obtains a pointer to the Cryptoki library's list of function pointers. The pointer * is stored in the {PKCS11::Library} object and used to call any Cryptoki functions. * * @see PKCS11::Library#initialize */ static VALUE pkcs11_C_GetFunctionList(VALUE self) { pkcs11_ctx *ctx; CK_RV rv; CK_C_GetFunctionList func; Data_Get_Struct(self, pkcs11_ctx, ctx); #ifdef compile_for_windows func = (CK_C_GetFunctionList)GetProcAddress(ctx->module, "C_GetFunctionList"); if(!func){ char error_text[999] = "GetProcAddress() error"; FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_MAX_WIDTH_MASK, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&error_text, sizeof(error_text), NULL); rb_raise(ePKCS11Error, "%s", error_text); } #else func = (CK_C_GetFunctionList)dlsym(ctx->module, "C_GetFunctionList"); if(!func) rb_raise(ePKCS11Error, "%s", dlerror()); #endif CallFunction(C_GetFunctionList, func, rv, &(ctx->functions)); if (rv != CKR_OK) pkcs11_raise(self,rv); return self; }
void TestConstructorDestructor(clcpp::Database& db) { const clcpp::Class* ca = clcpp::GetType<TestClassImpl::A>()->AsClass(); const clcpp::Class* cb = clcpp::GetType<TestClassImpl::B>()->AsClass(); TestClassImpl::A* a = (TestClassImpl::A*)new char[sizeof(TestClassImpl::A)]; TestClassImpl::B* b = (TestClassImpl::B*)new char[sizeof(TestClassImpl::B)]; CallFunction(ca->constructor, a); CallFunction(cb->constructor, b); CallFunction(ca->destructor, a); CallFunction(cb->destructor, b); delete [] (char*) a; delete [] (char*) b; }
unsigned int YouTubeWebPageView::GetVideoBytesTotal() { CComVariant varResult; CallFunction(_T("getVideoBytesTotal"), std::vector<CComVariant>(), varResult); ATLASSERT(varResult.vt == VT_I4); return varResult.intVal; }
bool YouTubeWebPageView::IsMuted() { CComVariant varResult; CallFunction(_T("isMuted"), std::vector<CComVariant>(), varResult); ATLASSERT(varResult.vt == VT_BOOL); return varResult.boolVal == VARIANT_TRUE; }
clcpp::ReadIterator::~ReadIterator() { // Destruct the read iterator if (m_IteratorImplType != 0) CallFunction(m_IteratorImplType->destructor, (IReadIterator*)m_ImplData); else clcpp::internal::CallDestructor((ArrayReadIterator*)m_ImplData); }
DisableCalculation::DisableCalculation() { calulationState_ = CallFunction(xlfGetDocument, 14, "Get Document properies for calculation").AsInt(); if(calulationState_ < 3) { CallCommand(xlcOptionsCalculation, 3, "Set calculation optiosn"); } }
FnCallResult FnCallEvaluate(EvalContext *ctx, FnCall *fp, const Promise *caller) { Rlist *expargs; const FnCallType *fp_type = FnCallTypeGet(fp->name); if (fp_type) { if (DEBUG) { printf("EVALUATE FN CALL %s\n", fp->name); FnCallShow(stdout, fp); printf("\n"); } } else { if (caller) { CfOut(OUTPUT_LEVEL_ERROR, "", "No such FnCall \"%s()\" in promise @ %s near line %zd\n", fp->name, PromiseGetBundle(caller)->source_path, caller->offset.line); } else { CfOut(OUTPUT_LEVEL_ERROR, "", "No such FnCall \"%s()\" - context info unavailable\n", fp->name); } return (FnCallResult) { FNCALL_FAILURE, { FnCallCopy(fp), RVAL_TYPE_FNCALL } }; } /* If the container classes seem not to be defined at this stage, then don't try to expand the function */ if ((caller != NULL) && !IsDefinedClass(ctx, caller->classes, PromiseGetNamespace(caller))) { return (FnCallResult) { FNCALL_FAILURE, { FnCallCopy(fp), RVAL_TYPE_FNCALL } }; } expargs = NewExpArgs(ctx, fp, caller); if (UnresolvedArgs(expargs)) { DeleteExpArgs(expargs); return (FnCallResult) { FNCALL_FAILURE, { FnCallCopy(fp), RVAL_TYPE_FNCALL } }; } fp->caller = caller; FnCallResult result = CallFunction(ctx, fp_type, fp, expargs); if (result.status == FNCALL_FAILURE) { /* We do not assign variables to failed function calls */ DeleteExpArgs(expargs); return (FnCallResult) { FNCALL_FAILURE, { FnCallCopy(fp), RVAL_TYPE_FNCALL } }; } DeleteExpArgs(expargs); return result; }
cLuaInterpreter::~cLuaInterpreter() { char * args[] = { NULL }; if(mL) { CallFunction("UnLoad", args); lua_close(mL); } clean(); }
static VALUE pkcs11_C_GetOperationState(VALUE self, VALUE session) { CK_RV rv; CK_C_GetOperationState func; VALUE state; CK_ULONG size; GetFunction(self, C_GetOperationState, func); CallFunction(C_GetOperationState, func, rv, NUM2HANDLE(session), NULL_PTR, &size); if (rv != CKR_OK) pkcs11_raise(self,rv); state = rb_str_new(0, size); CallFunction(C_GetOperationState, func, rv, NUM2HANDLE(session), (CK_BYTE_PTR)RSTRING_PTR(state), &size); if (rv != CKR_OK) pkcs11_raise(self,rv); rb_str_set_len(state, size); return state; }
FnCallResult EvaluateFunctionCall(FnCall *fp, Promise *pp) { Rlist *expargs; const FnCallType *this = FindFunction(fp->name); if (this) { if (DEBUG) { printf("EVALUATE FN CALL %s\n", fp->name); ShowFnCall(stdout, fp); printf("\n"); } } else { if (pp) { CfOut(cf_error, "", "No such FnCall \"%s()\" in promise @ %s near line %zd\n", fp->name, pp->audit->filename, pp->offset.line); } else { CfOut(cf_error, "", "No such FnCall \"%s()\" - context info unavailable\n", fp->name); } return (FnCallResult) { FNCALL_FAILURE, { CopyFnCall(fp), CF_FNCALL } }; } /* If the container classes seem not to be defined at this stage, then don't try to expand the function */ if ((pp != NULL) && !IsDefinedClass(pp->classes)) { return (FnCallResult) { FNCALL_FAILURE, { CopyFnCall(fp), CF_FNCALL } }; } expargs = NewExpArgs(fp, pp); if (UnresolvedArgs(expargs)) { DeleteExpArgs(expargs); return (FnCallResult) { FNCALL_FAILURE, { CopyFnCall(fp), CF_FNCALL } }; } FnCallResult result = CallFunction(this, fp, expargs); if (result.status == FNCALL_FAILURE) { /* We do not assign variables to failed function calls */ DeleteExpArgs(expargs); return (FnCallResult) { FNCALL_FAILURE, { CopyFnCall(fp), CF_FNCALL } }; } DeleteExpArgs(expargs); return result; }
void cPlugin_NewLua::OnDisable() { cCSLock Lock(m_CriticalSection); if (!PushFunction("OnDisable", false)) // false = don't log error if not found { return; } CallFunction(0, 0, "OnDisable"); }
clcpp::WriteIterator::~WriteIterator() { if (m_Initialised) { // Destruct the write iterator if (m_IteratorImplType != 0) CallFunction(m_IteratorImplType->destructor, (IWriteIterator*)m_ImplData); else clcpp::internal::CallDestructor((ArrayWriteIterator*)m_ImplData); } }
// Calls a Lua function from a given keyname bool _Scripting::HandleKeyPress(int Key) { // Find function KeyCallbacksIterator = KeyCallbacks.find(Key); if(KeyCallbacksIterator != KeyCallbacks.end()) { CallFunction(KeyCallbacksIterator->second); return true; } return false; }
TInt RTFDosExtension::CallSyncDosExtFunction( const TInt& aFunc, TAny* aParam = NULL, TInt aParLength = 0, TBool aAutoComplete = ETrue ) { COMPONENT_TRACE( ( _L( " DSYTESTTOOL - RTFDosExtension::CallSyncDosExtFunction(0x%x, 0x%x, 0x%x, 0x%x)" ), aFunc, aParam, aParLength, aAutoComplete ) ); TExtensionParPckg package; package().iFunc = aFunc; package().iParLength = aParLength; package().iAutoComplete = aAutoComplete; TPtr8 ptr( ( TUint8* )aParam, aParLength, aParLength ); TInt result = CallFunction( package, ptr ); COMPONENT_TRACE( ( _L( " DSYTESTTOOL - RTFDosExtension::CallSyncDosExtFunction - return 0x%x" ), result ) ); return result; }
void cLuaInterpreter::Load() { // call Main() first if exists char * args[] = { (char *)mScriptName.c_str(), // set first argument to script name, could be useful for path detection NULL }; CallFunction("Main", args); //if (!CallFunction("Main", args)) @todo: unload self }
static VALUE pkcs11_C_CloseSession(VALUE self, VALUE session) { CK_C_CloseSession func; CK_RV rv; GetFunction(self, C_CloseSession, func); CallFunction(C_CloseSession, func, rv, NUM2HANDLE(session)); if(rv != CKR_OK) pkcs11_raise(self,rv); return self; }
/* * Is called to indicate that an application is finished with the Cryptoki library. * @see PKCS11::Library#close */ static VALUE pkcs11_C_Finalize(VALUE self) { CK_C_Finalize func; CK_RV rv; GetFunction(self, C_Finalize, func); CallFunction(C_Finalize, func, rv, NULL_PTR); if (rv != CKR_OK) pkcs11_raise(self,rv); return self; }
static VALUE pkcs11_C_CloseAllSessions(VALUE self, VALUE slot_id) { CK_C_CloseAllSessions func; CK_RV rv; GetFunction(self, C_CloseAllSessions, func); CallFunction(C_CloseAllSessions, func, rv, NUM2HANDLE(slot_id)); if(rv != CKR_OK) pkcs11_raise(self,rv); return self; }