Ejemplo n.º 1
0
int mesage_SaveFieldBinary(lua_State* L) {
	int err = 0;
	char *b = NULL;
	CMessage* msg = cmessage_arg(L, "mesage_AddFieldBinary");
	CString fldName = luaL_checkstring(L, 2);
	CString path = luaL_checkstring(L, 3);
	char *description;
	DWORD l;

	CDatum *d = msg->GetDatum(fldName);
	if (d->GetVarType() != (VT_ARRAY | VT_UI1) ) {
		err = -1;
		description = "Not Binary Data";
		goto err;
	}
	{
		l = d->GetDataSize();
		b = new char[l];


		SAFEARRAY* pArray = d->value().parray;
		ASSERT(pArray->cDims == 1); // check we have 1 dimension array
		ASSERT(l == pArray->rgsabound[0].cElements * pArray->cbElements); // get size of array
		memcpy(b, (BYTE*)pArray->pvData, l);

		int charsLen = ::MultiByteToWideChar(CP_UTF8, 0, path, lstrlen(path), NULL, 0);
		std::wstring characters(charsLen, '\0');
		::MultiByteToWideChar(CP_UTF8, 0, path, lstrlen(path), &characters[0], charsLen);

		int pf;

		err = _wsopen_s(&pf, characters.c_str(), _O_BINARY | _O_CREAT | _O_TRUNC | _O_WRONLY, _SH_DENYRW, _S_IWRITE);
		if (err) {
			description = "Open File Error";
			goto err;
		}
		if (l != _write(pf, (b), l)) {
			err = -2;
			description = "Write File Error";
			goto err;
		}

		err = _close(pf);
		if (err){
			description = "Close File Error";
			goto err;
		}
	}
err:
	if (b)
		delete[]b;
	lua_pushinteger(L, err);
	if (err)
		lua_pushstring(L, description);
	else
		lua_pushinteger(L, l);
	return 2;
}
Ejemplo n.º 2
0
int mesage_Field(lua_State* L){
	CString type = luaL_typename(L, 2);
	CMessage* msg = cmessage_arg(L, "mesage_Field");
	CDatum* d;
	if(type == "string")
		d = msg->GetDatum(luaL_checkstring(L, 2));
	else
		d = msg->GetDatum(luaL_checkint(L, 2));

	if (!d) return 0;
	switch (d->GetVarType())
	{
	case VT_R8:
	{
		double i;
		d->GetValueAsDouble(i);
		lua_pushnumber(L, i);
	}
		break;
	case VT_I4:
	{
		long i;
		d->GetValueAsLong(i);
		lua_pushinteger(L, i);
	}
		break;
	case VT_BOOL:
	{
		bool i;
		d->GetValueAsBool(i);
		lua_pushboolean(L, i);
	}
		break;
	case VT_BSTR:
	case VT_DATE:
		lua_pushstring(L, d->GetValueText());
		break;
	default:
		lua_pushnil(L);
	}
	return 1;
}
Ejemplo n.º 3
0
int mesage_GetPathValue(lua_State* L)
{
	CString path = luaL_checkstring(L,2);
	CMessage* msg = cmessage_arg(L,"mesage_GetPathValue");
	CDatum* d = msg->GetDatumByPath(path);
	if(!d) return 0;
	switch(d->GetVarType())
	{
	case VT_R8:
		{
			double i;
			d->GetValueAsDouble(i);
			lua_pushnumber(L, i);
		}
		break;
	case VT_I4:
		{
			long i;
			d->GetValueAsLong(i);
			lua_pushinteger(L, i);
		}
		break;
	case VT_BOOL:
		{
			bool i;
			d->GetValueAsBool(i);
			lua_pushboolean(L, i);
		}
		break;
	case VT_BSTR:
	case VT_DATE:
		lua_pushstring(L, d->GetValueText());
		break;
	default:
		lua_pushnil(L);
	}
	return 1;
}