-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rubyize.cpp
executable file
·212 lines (195 loc) · 5.53 KB
/
Rubyize.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
* Copyright(c) 2009 arton
*
* You may distribute under the terms of either the GNU General Public
* License
*
* $Date$
*/
#include "stdafx.h"
#ifdef _MERGE_PROXYSTUB
#include "RScript.h"
#else
#include "GRScript.h"
#endif
#include "Rubyize.h"
#define RUBYIZE_VERSION L"1.9.1"
#define RUBYIZE NULL
/////////////////////////////////////////////////////////////////////////////
// CRubyize
HRESULT CRubyize::FinalConstruct()
{
#ifndef __IRubyWrapper_INTERFACE_DEFINED__
HRESULT hr = CComObject<CGlobalRubyScript>::CreateInstance(&m_pRubyScript);
#else
HRESULT hr = CComObject<CRubyScript>::CreateInstance(&m_pRubyScript);
#endif
if (hr == S_OK)
{
m_pRubyScript->AddRef();
m_pRubyScript->SetScriptSite(this);
CComPtr<IActiveScriptParse> pParse;
HRESULT hr = m_pRubyScript->QueryInterface(IID_IActiveScriptParse, (void**)&pParse);
if (hr == S_OK)
{
pParse->InitNew();
hr = pParse->ParseScriptText(
L"def rubyize(str)\n"
L"ActiveScriptRuby.rubyize true\n"
L" str\n"
L"end\n"
L"def erubyize(str)\n"
L" ActiveScriptRuby.rubyize true\n"
L" eval str\n"
L"end\n"
L"def ruby_version\n"
L" %|#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}|\n"
L"end\n",
RUBYIZE,
NULL,
NULL,
NULL,
1,
SCRIPTTEXT_ISVISIBLE,
NULL,
NULL);
if (hr == S_OK)
{
m_pRubyScript->SetScriptState(SCRIPTSTATE_CONNECTED);
}
}
}
return hr;
}
void CRubyize::FinalRelease()
{
if (m_pRubyScript)
{
m_pRubyScript->Close();
m_pRubyScript->Release();
m_pRubyScript = NULL;
}
}
HRESULT STDMETHODCALLTYPE CRubyize::GetLCID(
/* [out] */ LCID __RPC_FAR *plcid)
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE CRubyize::GetItemInfo(
/* [in] */ LPCOLESTR pstrName,
/* [in] */ DWORD dwReturnMask,
/* [out] */ IUnknown __RPC_FAR *__RPC_FAR *ppiunkItem,
/* [out] */ ITypeInfo __RPC_FAR *__RPC_FAR *ppti)
{
return TYPE_E_ELEMENTNOTFOUND;
}
HRESULT STDMETHODCALLTYPE CRubyize::GetDocVersionString(
/* [out] */ BSTR __RPC_FAR *pbstrVersion)
{
*pbstrVersion = SysAllocString(RUBYIZE_VERSION);
return S_OK;
}
HRESULT STDMETHODCALLTYPE CRubyize::OnScriptTerminate(
/* [in] */ const VARIANT __RPC_FAR *pvarResult,
/* [in] */ const EXCEPINFO __RPC_FAR *pexcepinfo)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE CRubyize::OnStateChange(
/* [in] */ SCRIPTSTATE ssScriptState)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE CRubyize::OnScriptError(
/* [in] */ IActiveScriptError __RPC_FAR *pscripterror)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE CRubyize::OnEnterScript( void)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE CRubyize::OnLeaveScript( void)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE CRubyize::get_Version(
/* [retval][out] */ BSTR __RPC_FAR *pVersion)
{
if (!pVersion) return E_POINTER;
*pVersion = SysAllocString(RUBYIZE_VERSION);
return S_OK;
}
HRESULT STDMETHODCALLTYPE CRubyize::get_RubyVersion(
/* [retval][out] */ BSTR __RPC_FAR *pVersion)
{
if (!pVersion) return E_POINTER;
VARIANT v;
VariantInit(&v);
HRESULT hr = Call(L"ruby_version", 0, NULL, &v);
if (hr == S_OK)
{
if (v.vt == VT_BSTR)
{
*pVersion = SysAllocString(v.bstrVal);
}
else if (v.vt == (VT_BSTR | VT_BYREF))
{
*pVersion = SysAllocString(*v.pbstrVal);
}
else
{
*pVersion = NULL;
}
VariantClear(&v);
}
return hr;
}
HRESULT CRubyize::Call(LPCOLESTR method, int cargs, VARIANT* args, VARIANT* pResult)
{
CComPtr<IDispatch> pdisp;
HRESULT hr = m_pRubyScript->GetScriptDispatch(RUBYIZE, &pdisp);
if (hr == S_OK)
{
DISPID dispid[1];
hr = pdisp->GetIDsOfNames(IID_NULL, const_cast<LPOLESTR*>(&method), 1, LOCALE_SYSTEM_DEFAULT, dispid);
if (hr == S_OK)
{
DISPPARAMS params = { args, NULL, cargs, 0 };
unsigned int aerr;
hr = pdisp->Invoke(dispid[0], IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD,
¶ms, pResult, NULL, &aerr);
}
}
return hr;
}
HRESULT STDMETHODCALLTYPE CRubyize::rubyize(
/* [in] */ VARIANT val,
/* [retval][out] */ VARIANT __RPC_FAR *pObj)
{
if (!pObj) return E_POINTER;
return Call(L"rubyize", 1, &val, pObj);
}
HRESULT STDMETHODCALLTYPE CRubyize::erubyize(
/* [in] */ BSTR script,
/* [retval][out] */ VARIANT __RPC_FAR *pObj)
{
if (!pObj) return E_POINTER;
VARIANT v;
v.vt = VT_BSTR;
v.bstrVal = script;
return Call(L"erubyize", 1, &v, pObj);
}
STDMETHODIMP CRubyize::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_IRubyize
};
for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
{
if (InlineIsEqualGUID(*arr[i],riid))
return S_OK;
}
return S_FALSE;
}