Skip to content

Commit 4da740e

Browse files
author
Fraser J. Gordon
committed
Plumb libscript into the Win32 project files
1 parent 715e222 commit 4da740e

File tree

11 files changed

+311
-13
lines changed

11 files changed

+311
-13
lines changed

engine/engine.vcproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@
209209
ReferencedProjectIdentifier="{0491E47C-B996-4DBF-8D26-C88263DF6176}"
210210
RelativePathToProject=".\engine\kernel-development.vcproj"
211211
/>
212+
<ProjectReference
213+
ReferencedProjectIdentifier="{25CCFCBE-CCB2-44FC-A4FB-F46990F4383A}"
214+
RelativePathToProject=".\thirdparty\libffi\libffi.vcproj"
215+
/>
212216
</References>
213217
<Files>
214218
<Filter

engine/kernel.vcproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
/>
3939
<Tool
4040
Name="VCCLCompilerTool"
41-
AdditionalIncludeDirectories="&quot;$(ProgramFiles)\QuickTime SDK\CIncludes&quot;"
41+
AdditionalIncludeDirectories="&quot;$(SolutionDir)libscript\include&quot;;&quot;$(ProgramFiles)\QuickTime SDK\CIncludes&quot;"
4242
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
4343
MinimalRebuild="true"
4444
BasicRuntimeChecks="3"
@@ -98,7 +98,7 @@
9898
/>
9999
<Tool
100100
Name="VCCLCompilerTool"
101-
AdditionalIncludeDirectories="&quot;$(ProgramFiles)\QuickTime SDK\CIncludes&quot;"
101+
AdditionalIncludeDirectories="&quot;$(SolutionDir)libscript\include&quot;;&quot;$(ProgramFiles)\QuickTime SDK\CIncludes&quot;"
102102
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
103103
UsePrecompiledHeader="2"
104104
PrecompiledHeaderThrough="prefix.h"
@@ -166,6 +166,10 @@
166166
ReferencedProjectIdentifier="{F9B1E2E6-8FD9-48C2-8D5C-9900865E7096}"
167167
RelativePathToProject=".\libgraphics\libgraphics.vcproj"
168168
/>
169+
<ProjectReference
170+
ReferencedProjectIdentifier="{E82DA459-E7D9-4D1A-96D1-F7EE03FC0BB1}"
171+
RelativePathToProject=".\libscript\libscript.vcproj"
172+
/>
169173
</References>
170174
<Files>
171175
<Filter

libscript/libscript.vcproj

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
<?xml version="1.0" encoding="Windows-1252"?>
2+
<VisualStudioProject
3+
ProjectType="Visual C++"
4+
Version="8.00"
5+
Name="libscript"
6+
ProjectGUID="{E82DA459-E7D9-4D1A-96D1-F7EE03FC0BB1}"
7+
>
8+
<Platforms>
9+
<Platform
10+
Name="Win32"
11+
/>
12+
</Platforms>
13+
<ToolFiles>
14+
</ToolFiles>
15+
<Configurations>
16+
<Configuration
17+
Name="Debug|Win32"
18+
ConfigurationType="4"
19+
InheritedPropertySheets="$(SolutionDir)rules\Global.vsprops;$(SolutionDir)rules\Debug.vsprops"
20+
>
21+
<Tool
22+
Name="VCPreBuildEventTool"
23+
/>
24+
<Tool
25+
Name="VCCustomBuildTool"
26+
/>
27+
<Tool
28+
Name="VCXMLDataGeneratorTool"
29+
/>
30+
<Tool
31+
Name="VCWebServiceProxyGeneratorTool"
32+
/>
33+
<Tool
34+
Name="VCMIDLTool"
35+
/>
36+
<Tool
37+
Name="VCCLCompilerTool"
38+
AdditionalIncludeDirectories="&quot;$(SolutionDir)engine\src&quot;;&quot;$(SolutionDir)thirdparty\libffi\win32&quot;;&quot;$(SolutionDir)libscript\include&quot;"
39+
/>
40+
<Tool
41+
Name="VCManagedResourceCompilerTool"
42+
/>
43+
<Tool
44+
Name="VCResourceCompilerTool"
45+
/>
46+
<Tool
47+
Name="VCPreLinkEventTool"
48+
/>
49+
<Tool
50+
Name="VCLibrarianTool"
51+
/>
52+
<Tool
53+
Name="VCALinkTool"
54+
/>
55+
<Tool
56+
Name="VCXDCMakeTool"
57+
/>
58+
<Tool
59+
Name="VCBscMakeTool"
60+
/>
61+
<Tool
62+
Name="VCFxCopTool"
63+
/>
64+
<Tool
65+
Name="VCPostBuildEventTool"
66+
/>
67+
</Configuration>
68+
<Configuration
69+
Name="Release|Win32"
70+
ConfigurationType="4"
71+
InheritedPropertySheets="$(SolutionDir)rules\Global.vsprops;$(SolutionDir)rules\Debug.vsprops"
72+
>
73+
<Tool
74+
Name="VCPreBuildEventTool"
75+
/>
76+
<Tool
77+
Name="VCCustomBuildTool"
78+
/>
79+
<Tool
80+
Name="VCXMLDataGeneratorTool"
81+
/>
82+
<Tool
83+
Name="VCWebServiceProxyGeneratorTool"
84+
/>
85+
<Tool
86+
Name="VCMIDLTool"
87+
/>
88+
<Tool
89+
Name="VCCLCompilerTool"
90+
AdditionalIncludeDirectories="&quot;$(SolutionDir)engine\src&quot;;&quot;$(SolutionDir)thirdparty\libffi\win32&quot;;&quot;$(SolutionDir)libscript\include&quot;"
91+
/>
92+
<Tool
93+
Name="VCManagedResourceCompilerTool"
94+
/>
95+
<Tool
96+
Name="VCResourceCompilerTool"
97+
/>
98+
<Tool
99+
Name="VCPreLinkEventTool"
100+
/>
101+
<Tool
102+
Name="VCLibrarianTool"
103+
/>
104+
<Tool
105+
Name="VCALinkTool"
106+
/>
107+
<Tool
108+
Name="VCXDCMakeTool"
109+
/>
110+
<Tool
111+
Name="VCBscMakeTool"
112+
/>
113+
<Tool
114+
Name="VCFxCopTool"
115+
/>
116+
<Tool
117+
Name="VCPostBuildEventTool"
118+
/>
119+
</Configuration>
120+
</Configurations>
121+
<References>
122+
</References>
123+
<Files>
124+
<Filter
125+
Name="Source Files"
126+
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
127+
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
128+
>
129+
<File
130+
RelativePath=".\src\module-arithmetic.cpp"
131+
>
132+
</File>
133+
<File
134+
RelativePath=".\src\module-binary.cpp"
135+
>
136+
</File>
137+
<File
138+
RelativePath=".\src\module-bitwise.cpp"
139+
>
140+
</File>
141+
<File
142+
RelativePath=".\src\module-byte.cpp"
143+
>
144+
</File>
145+
<File
146+
RelativePath=".\src\module-char.cpp"
147+
>
148+
</File>
149+
<File
150+
RelativePath=".\src\module-encoding.cpp"
151+
>
152+
</File>
153+
<File
154+
RelativePath=".\src\module-file.cpp"
155+
>
156+
</File>
157+
<File
158+
RelativePath=".\src\module-list.cpp"
159+
>
160+
</File>
161+
<File
162+
RelativePath=".\src\module-logic.cpp"
163+
>
164+
</File>
165+
<File
166+
RelativePath=".\src\module-map.cpp"
167+
>
168+
</File>
169+
<File
170+
RelativePath=".\src\module-math.cpp"
171+
>
172+
</File>
173+
<File
174+
RelativePath=".\src\module-math_foundation.cpp"
175+
>
176+
</File>
177+
<File
178+
RelativePath=".\src\module-sort.cpp"
179+
>
180+
</File>
181+
<File
182+
RelativePath=".\src\module-string.cpp"
183+
>
184+
</File>
185+
<File
186+
RelativePath=".\src\module-type.cpp"
187+
>
188+
</File>
189+
<File
190+
RelativePath=".\src\module-type_convert.cpp"
191+
>
192+
</File>
193+
<File
194+
RelativePath=".\src\module-url.cpp"
195+
>
196+
</File>
197+
<File
198+
RelativePath=".\src\script-builder.cpp"
199+
>
200+
</File>
201+
<File
202+
RelativePath=".\src\script-instance.cpp"
203+
>
204+
</File>
205+
<File
206+
RelativePath=".\src\script-module.cpp"
207+
>
208+
</File>
209+
<File
210+
RelativePath=".\src\script-object.cpp"
211+
>
212+
</File>
213+
<File
214+
RelativePath=".\src\script-package.cpp"
215+
>
216+
</File>
217+
<File
218+
RelativePath=".\src\script-private.h"
219+
>
220+
</File>
221+
</Filter>
222+
<Filter
223+
Name="Header Files"
224+
Filter="h;hpp;hxx;hm;inl;inc;xsd"
225+
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
226+
>
227+
<File
228+
RelativePath=".\include\script.h"
229+
>
230+
</File>
231+
</Filter>
232+
<Filter
233+
Name="Resource Files"
234+
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
235+
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
236+
>
237+
</Filter>
238+
</Files>
239+
<Globals>
240+
</Globals>
241+
</VisualStudioProject>

libscript/src/module-arithmetic.cpp

100644100755
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <foundation.h>
1818
#include <foundation-auto.h>
1919

20+
#include <float.h>
21+
2022
extern "C" void MCArithmeticExecAddIntegerToInteger(integer_t p_number, integer_t& x_target)
2123
{
2224
if (p_number > 0 && INTEGER_MAX - p_number < x_target)
@@ -117,7 +119,7 @@ extern "C" void MCArithmeticExecDivideIntegerByInteger(integer_t p_number, integ
117119

118120
extern "C" void MCArithmeticExecDivideRealByReal(double p_number, double& x_target)
119121
{
120-
if (p_number > 0 && p_number < 1 && MAXFLOAT * p_number < x_target)
122+
if (p_number > 0 && p_number < 1 && FLT_MAX * p_number < x_target)
121123
// overflow
122124
return;
123125
x_target /= p_number;
@@ -262,7 +264,7 @@ extern "C" void MCArithmeticEvalIntegerModInteger(integer_t p_left, integer_t p_
262264
if (p_right == 0)
263265
return;
264266

265-
r_output = fmod(p_left, p_right);
267+
r_output = fmod(double(p_left), double(p_right));
266268
}
267269

268270
extern "C" void MCArithmeticEvalRealModReal(double p_left, double p_right, double& r_output)
@@ -294,9 +296,9 @@ extern "C" void MCArithmeticEvalIntegerWrapInteger(integer_t p_left, integer_t p
294296
integer_t t_y;
295297
t_y = p_left > 0 ? p_right : -p_right;
296298
if (p_left >= 0)
297-
r_output = (fmod(p_left - 1, t_y) + 1);
299+
r_output = (fmod(double(p_left - 1), double(t_y)) + 1);
298300
else
299-
r_output = -(fmod(-p_left - 1, t_y) + 1);
301+
r_output = -(fmod(double(-p_left - 1), double(t_y)) + 1);
300302
}
301303

302304
extern "C" void MCArithmeticEvalRealWrapReal(double p_left, double p_right, double& r_output)

libscript/src/module-math.cpp

100644100755
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
#include <foundation.h>
1818
#include "foundation-math.h"
1919

20+
#include <float.h>
21+
22+
// Older versions of MSVC don't supply "trunc"
23+
#ifdef _WIN32
24+
double trunc(double f) { return f < 0 ? ceil(f) : floor(f); }
25+
#endif
26+
2027
void MCMathEvalRealToPowerOfReal(double p_left, double p_right, double& r_output)
2128
{
2229
if (p_right == 0)
@@ -25,7 +32,7 @@ void MCMathEvalRealToPowerOfReal(double p_left, double p_right, double& r_output
2532
return;
2633
}
2734

28-
if (p_right > 0 && p_left > 0 && p_left > (log(MAXFLOAT)/log(p_right)))
35+
if (p_right > 0 && p_left > 0 && p_left > (log(FLT_MAX)/log(p_right)))
2936
{
3037
// overflow
3138
return;

libscript/src/script-instance.cpp

100644100755
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#include "script.h"
22
#include "script-private.h"
33

4-
#include <ffi/ffi.h>
4+
#include "ffi.h"
5+
6+
#ifdef _WIN32
7+
#include <windows.h>
8+
#else
59
#include <dlfcn.h>
10+
#endif
611

712
////////////////////////////////////////////////////////////////////////////////
813

@@ -708,7 +713,11 @@ static bool MCScriptPerformScriptInvoke(MCScriptFrame*& x_frame, byte_t*& x_next
708713

709714
static bool MCScriptPrepareForeignFunction(MCScriptFrame *p_frame, MCScriptInstanceRef p_instance, MCScriptForeignHandlerDefinition *p_handler)
710715
{
716+
#ifdef _WIN32
717+
p_handler -> function = GetProcAddress(GetModuleHandle(NULL), MCStringGetCString(p_handler -> binding));
718+
#else
711719
p_handler -> function = dlsym(RTLD_DEFAULT, MCStringGetCString(p_handler -> binding));
720+
#endif
712721
if (p_handler -> function == nil)
713722
return MCErrorThrowGeneric();
714723

libscript/src/script-module.cpp

100644100755
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
#include "script-private.h"
66

77
#include <stddef.h>
8+
9+
#ifdef _WIN32
10+
#include <windows.h>
11+
#else
812
#include <dlfcn.h>
13+
#endif
914

1015
////////////////////////////////////////////////////////////////////////////////
1116

@@ -547,7 +552,11 @@ bool MCScriptEnsureModuleIsUsable(MCScriptModuleRef self)
547552
t_type = static_cast<MCScriptForeignType *>(self -> types[i]);
548553

549554
void *t_symbol;
555+
#ifdef _WIN32
556+
t_symbol = GetProcAddress(GetModuleHandle(NULL), MCStringGetCString(t_type -> binding));
557+
#else
550558
t_symbol = dlsym(RTLD_DEFAULT, MCStringGetCString(t_type -> binding));
559+
#endif
551560
if (t_symbol == nil)
552561
{
553562
MCLog("Unable to resolve foreign type '%@'", t_type -> binding);

0 commit comments

Comments
 (0)