Beispiel #1
0
//----------------------------------------------------------------------
// 配列を作成
tTJSVariant createArray(void)
{
	iTJSDispatch2 *obj = TJSCreateArrayObject();
	tTJSVariant result(obj, obj);
	obj->Release();
	return result;
}
Beispiel #2
0
/**
 * XMLのノードから tTJSVariantを取得する
 * @param var 結果格納先
 * @param node ノード
 */
static void
getVariantFromNode(tTJSVariant &var, xml_node *node)
{
	if (node && node->type() == rapidxml::node_element) {
		if (_wcsicmp(node->name(), L"undefined") == 0) {
			var.Clear();
		} else if (_wcsicmp(node->name(), L"null") == 0) {
			var = tTJSVariant((iTJSDispatch2*)NULL);
		} else if (_wcsicmp(node->name(), L"array") == 0) {
			iTJSDispatch2 *array = TJSCreateArrayObject();
			for (xml_node *propNode = node->first_node(); propNode; propNode = propNode->next_sibling()) {
				if (_wcsicmp(propNode->name(), L"property") == 0) {
					xml_attribute *attr_id = propNode->first_attribute(L"id");
					if (attr_id) {
						tjs_int id = wcstol(attr_id->value(), NULL, 10);
						xml_node *valueNode = propNode->first_node();
						if (valueNode) {
							tTJSVariant value;
							getVariantFromNode(value, valueNode);
							array->PropSetByNum(0, id, &value, array);
						}
					}
				}
			}
			var = tTJSVariant(array, array);
			array->Release();
		} else if (_wcsicmp(node->name(), L"object") == 0) {
			iTJSDispatch2 *dict = TJSCreateDictionaryObject();
			for (xml_node *propNode = node->first_node(); propNode; propNode = propNode->next_sibling()) {
				if (_wcsicmp(propNode->name(), L"property") == 0) {
					xml_attribute *attr_id = propNode->first_attribute(L"id");
					if (attr_id) {
						ttstr id = attr_id->value();
						if (id.length() > 0) {
							xml_node *valueNode = propNode->first_node();
							if (valueNode) {
								tTJSVariant value;
								getVariantFromNode(value, valueNode);
								dict->PropSet(0, id.c_str(), 0, &value, dict);
							}
						}
					}
				}
			}
			var = tTJSVariant(dict, dict);
			dict->Release();
		} else if (_wcsicmp(node->name(), L"string") == 0) {
			var = node->value();
		} else if (_wcsicmp(node->name(), L"number") == 0) {
			var = wcstod(node->value(), NULL);
		}
	} else {
		var.Clear();
	}
}
Beispiel #3
0
//----------------------------------------------------------------------
// 構造体比較関数
tTJSVariant
ScriptsAdd::clone(tTJSVariant obj)
{
	// タイプがオブジェクトなら細かく判定
	if (obj.Type() == tvtObject) {

		tTJSVariantClosure &o1 = obj.AsObjectClosureNoAddRef();
		
		// Arrayの複製
		if (o1.IsInstanceOf(0, NULL, NULL, L"Array", NULL)== TJS_S_TRUE) {
			iTJSDispatch2 *array = TJSCreateArrayObject();
			tTJSVariant o1Count;
			(void)o1.PropGet(0, L"count", &countHint, &o1Count, NULL);
			tjs_int count = o1Count;
			tTJSVariant val;
			tTJSVariant *args[] = {&val};
			for (tjs_int i = 0; i < count; i++) {
				(void)o1.PropGetByNum(TJS_IGNOREPROP, i, &val, NULL);
				val = ScriptsAdd::clone(val);
				static tjs_uint addHint = 0;
				(void)array->FuncCall(0, TJS_W("add"), &addHint, 0, 1, args, array);
			}
			tTJSVariant result(array, array);
			array->Release();
			return result;
		}
		
		// Dictionaryの複製
		if (o1.IsInstanceOf(0, NULL, NULL, L"Dictionary", NULL)== TJS_S_TRUE) {
			iTJSDispatch2 *dict = TJSCreateDictionaryObject();
			DictMemberCloneCaller *caller = new DictMemberCloneCaller(dict);
			tTJSVariantClosure closure(caller);
			o1.EnumMembers(TJS_IGNOREPROP, &closure, NULL);
			caller->Release();
			tTJSVariant result(dict, dict);
			dict->Release();
			return result;
		}

		// cloneメソッドの呼び出しに成功すればそれを返す
		tTJSVariant result;
		static tjs_uint cloneHint = 0;
		if (o1.FuncCall(0, L"clone", &cloneHint, &result, 0, NULL, NULL)== TJS_S_TRUE) {
			return result;
		}
	}
	
	return obj;
}
Beispiel #4
0
/**
 * コマンドライン呼び出し
 */
tjs_error TJS_INTF_METHOD commandExecute(
	tTJSVariant *result, tjs_int numparams, tTJSVariant **param, iTJSDispatch2 *objthis)
{
	tTJSVariant vStdOut;

	// パラメータチェック
	if (numparams == 0) return TJS_E_BADPARAMCOUNT;
	if (param[0]->Type() != tvtString) return TJS_E_INVALIDPARAM;

	// コマンドライン/タイムアウト取得
	int timeout = 0;
	ttstr target(param[0]->GetString());
	const tjs_char *cmdprm = 0;

	if (numparams > 1) cmdprm  = param[1]->GetString();
	if (numparams > 2) timeout = (tjs_int)*param[2];

	DWORD exit = ~0L;
	bool haserr = true, timeouted = false;
	LPCWSTR errmes = 0;

	iTJSDispatch2 *array = TJSCreateArrayObject();
	if (array != 0) {
		CommandExecute exec;
		if (exec.start(target, cmdprm)) exec.wait(cmdExecLineCallback, array, timeout);
		exit = exec.getExitCode(&haserr, &timeouted, &errmes);

		vStdOut.SetObject(array, array);
		array->Release();
	}

	ncbDictionaryAccessor ret;
	if (ret.IsValid()) {
		ret.SetValue(L"stdout", vStdOut);
		if (haserr && errmes != 0) {
			ret.SetValue(L"status", ttstr(timeouted ? L"timeout" : L"error"));
			ret.SetValue(L"message", ttstr(errmes));
		} else {
			ret.SetValue(L"status", ttstr(haserr ? L"failed" : L"ok"));
			ret.SetValue(L"exitcode", (tjs_int)exit);
		}
	}
	if (result != NULL) *result = ret;
	return TJS_S_OK;
}
Beispiel #5
0
	/**
	 * メンバ名一覧の取得
	 */
tjs_error TJS_INTF_METHOD
ScriptsAdd::getKeys(tTJSVariant *result,
					tjs_int numparams,
					tTJSVariant **param,
					iTJSDispatch2 *objthis)
{
	if (numparams < 1) return TJS_E_BADPARAMCOUNT;
	if (result) {
		iTJSDispatch2 *array = TJSCreateArrayObject();
		DictMemberGetCaller *caller = new DictMemberGetCaller(array);
		tTJSVariantClosure closure(caller);
		param[0]->AsObjectClosureNoAddRef().EnumMembers(TJS_IGNOREPROP, &closure, NULL);
		caller->Release();
		*result = tTJSVariant(array, array);
		array->Release();
	}
	return TJS_S_OK;
}
tTJSArrayObject* tTJSBinarySerializer::CreateArray( tjs_uint count ) {
	tTJSArrayObject* array = (tTJSArrayObject*)TJSCreateArrayObject();
	return array;
}
Beispiel #7
0
//---------------------------------------------------------------------------
tjs_error TJS_INTF_METHOD tTJSDictionaryNI::tAssignStructCallback::FuncCall(
	tjs_uint32 flag, const tjs_char * membername, tjs_uint32 *hint,
	tTJSVariant *result, tjs_int numparams, tTJSVariant **param,
	iTJSDispatch2 *objthis)
{
	// called indirectly from tTJSDictionaryNI::AssignStructure or
	// tTJSArrayNI::AssignStructure

	if(numparams < 3) return TJS_E_BADPARAMCOUNT;

	// hidden members are not processed
	tjs_uint32 flags = (tjs_int)*param[1];
	if(flags & TJS_HIDDENMEMBER)
	{
		if(result) *result = (tjs_int)1;
		return TJS_S_OK;
	}

	tTJSVariant &value = *param[2];

	tTJSVariantType type = value.Type();
	if(type == tvtObject)
	{
		// object

		iTJSDispatch2 *dsp = value.AsObjectNoAddRef();
		// determin dsp's object type

		tTJSVariant val;

		tTJSDictionaryNI *dicni = NULL;
		tTJSArrayNI *arrayni = NULL;

		if(dsp && TJS_SUCCEEDED(dsp->NativeInstanceSupport(TJS_NIS_GETINSTANCE,
			TJSGetDictionaryClassID(), (iTJSNativeInstance**)&dicni)) )
		{
			// dictionary
			bool objrec = false;
			std::vector<iTJSDispatch2 *>::iterator i;
			for(i = Stack->begin(); i != Stack->end(); i++)
			{
				if(*i == dsp)
				{
					// object recursion detected
					objrec = true;
					break;
				}
			}
			if(objrec)
			{
				val.SetObject(NULL); // becomes null
			}
			else
			{
				iTJSDispatch2 * newobj = TJSCreateDictionaryObject();
				val.SetObject(newobj, newobj);
				newobj->Release();
				tTJSDictionaryNI * newni = NULL;
				if(TJS_SUCCEEDED(newobj->NativeInstanceSupport(TJS_NIS_GETINSTANCE,
					TJSGetDictionaryClassID(), (iTJSNativeInstance**)&newni)) )
				{
					newni->AssignStructure(dsp, *Stack);
				}
			}
		}
		else if(dsp && TJS_SUCCEEDED(dsp->NativeInstanceSupport(TJS_NIS_GETINSTANCE,
			TJSGetArrayClassID(), (iTJSNativeInstance**)&arrayni)) )
		{
			// array
			bool objrec = false;
			std::vector<iTJSDispatch2 *>::iterator i;
			for(i = Stack->begin(); i != Stack->end(); i++)
			{
				if(*i == dsp)
				{
					// object recursion detected
					objrec = true;
					break;
				}
			}
			if(objrec)
			{
				val.SetObject(NULL); // becomes null
			}
			else
			{
				iTJSDispatch2 * newobj = TJSCreateArrayObject();
				val.SetObject(newobj, newobj);
				newobj->Release();
				tTJSArrayNI * newni = NULL;
				if(TJS_SUCCEEDED(newobj->NativeInstanceSupport(TJS_NIS_GETINSTANCE,
					TJSGetArrayClassID(), (iTJSNativeInstance**)&newni)) )
				{
					newni->AssignStructure(dsp, *Stack);
				}
			}
		}
		else
		{
			// other object types
			val = value;
		}

		Dest->PropSetByVS(TJS_MEMBERENSURE|TJS_IGNOREPROP, param[0]->AsStringNoAddRef(), &val, Dest);
	}
	else
	{
		// other types
		Dest->PropSetByVS(TJS_MEMBERENSURE|TJS_IGNOREPROP, param[0]->AsStringNoAddRef(), &value, Dest);
	}

	if(result) *result = (tjs_int)1;
	return TJS_S_OK;
}