Skip to content

Commit d5dd289

Browse files
committed
[LCB] "foreign type" declarations bind to functions, not variables.
Change the meaning of the `foreign type <Name> binds to "<Symbol>"` syntax. `<Symbol>` is now expected to refer to a function with the signature `MCTypeInfoRef (*)(void)`, which returns a type info pointer. This is required for platforms which can dynamically resolve symbols referring to functions, such as Emscripten.
1 parent b39e466 commit d5dd289

File tree

8 files changed

+51
-49
lines changed

8 files changed

+51
-49
lines changed

engine/src/canvas.mlc

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,44 +25,44 @@ use com.livecode.foreign
2525
public type CanvasFloat is CFloat
2626

2727
// Point
28-
public foreign type Point binds to "kMCCanvasPointTypeInfo"
28+
public foreign type Point binds to "MCCanvasPointTypeInfo"
2929

3030
// Rectangle
31-
public foreign type Rectangle binds to "kMCCanvasRectangleTypeInfo"
31+
public foreign type Rectangle binds to "MCCanvasRectangleTypeInfo"
3232

3333
// Transform
34-
public foreign type Transform binds to "kMCCanvasTransformTypeInfo"
34+
public foreign type Transform binds to "MCCanvasTransformTypeInfo"
3535

3636
// Color
37-
public foreign type Color binds to "kMCCanvasColorTypeInfo"
37+
public foreign type Color binds to "MCCanvasColorTypeInfo"
3838

3939
// Paint (supertype of pattern, gradient, solidpaint)
40-
public foreign type Paint binds to "kMCCanvasPaintTypeInfo"
40+
public foreign type Paint binds to "MCCanvasPaintTypeInfo"
4141

4242
// Solid Paint
43-
public foreign type SolidPaint binds to "kMCCanvasSolidPaintTypeInfo"
43+
public foreign type SolidPaint binds to "MCCanvasSolidPaintTypeInfo"
4444

4545
// Pattern
46-
public foreign type Pattern binds to "kMCCanvasPatternTypeInfo"
46+
public foreign type Pattern binds to "MCCanvasPatternTypeInfo"
4747

4848
// Gradient
49-
public foreign type Gradient binds to "kMCCanvasGradientTypeInfo"
50-
public foreign type GradientStop binds to "kMCCanvasGradientStopTypeInfo"
49+
public foreign type Gradient binds to "MCCanvasGradientTypeInfo"
50+
public foreign type GradientStop binds to "MCCanvasGradientStopTypeInfo"
5151

5252
// Image
53-
public foreign type Image binds to "kMCCanvasImageTypeInfo"
53+
public foreign type Image binds to "MCCanvasImageTypeInfo"
5454

5555
// Path
56-
public foreign type Path binds to "kMCCanvasPathTypeInfo"
56+
public foreign type Path binds to "MCCanvasPathTypeInfo"
5757

5858
// Effect
59-
public foreign type Effect binds to "kMCCanvasEffectTypeInfo"
59+
public foreign type Effect binds to "MCCanvasEffectTypeInfo"
6060

6161
// Font
62-
public foreign type Font binds to "kMCCanvasFontTypeInfo"
62+
public foreign type Font binds to "MCCanvasFontTypeInfo"
6363

6464
// Canvas
65-
public foreign type Canvas binds to "kMCCanvasTypeInfo"
65+
public foreign type Canvas binds to "MCCanvasTypeInfo"
6666

6767
////////////////////////////////////////////////////////////////////////////////
6868
// Rectangle

engine/src/engine.mlc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module com.livecode.engine
3737

3838
use com.livecode.foreign
3939

40-
public foreign type ScriptObject binds to "kMCEngineScriptObjectTypeInfo"
40+
public foreign type ScriptObject binds to "MCEngineScriptObjectTypeInfo"
4141

4242
public foreign handler MCEngineExecResolveScriptObject(in pObjectId as String) returns ScriptObject binds to "<builtin>"
4343
public foreign handler MCEngineEvalScriptObjectExists(in pObject as ScriptObject, out rExists as CBool) returns nothing binds to "<builtin>"

engine/src/widget.mlc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ end syntax
586586

587587
// ---------- Synchronous and asynchronous ("current") event information ---------- //
588588

589-
//foreign type PressedState binds to "kMCPressedState"
589+
//foreign type PressedState binds to "MCPressedState"
590590

591591
public foreign handler MCWidgetGetMousePosition(in pCurrent as CBool, out rLocation as Point) returns nothing binds to "<builtin>"
592592
public foreign handler MCWidgetGetClickPosition(in pCurrent as CBool, out rLocation as Point) returns nothing binds to "<builtin>"
@@ -969,7 +969,7 @@ end syntax
969969

970970
// annotation <name> of <widget>
971971

972-
public foreign type Widget binds to "kMCWidgetTypeInfo"
972+
public foreign type Widget binds to "MCWidgetTypeInfo"
973973

974974
public foreign handler MCWidgetEvalTheTarget(out rTarget as optional Widget) returns nothing binds to "<builtin>"
975975

libscript/src/foreign.mlc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ module com.livecode.foreign
2020
-- Universal types
2121
----------------------------------------------------------------
2222

23-
public foreign type Pointer binds to "kMCPointerTypeInfo"
23+
public foreign type Pointer binds to "MCForeignPointerTypeInfo"
2424

25-
public foreign type UInt32 binds to "kMCUIntTypeInfo"
26-
public foreign type Int32 binds to "kMCIntTypeInfo"
25+
public foreign type UInt32 binds to "MCForeignUIntTypeInfo"
26+
public foreign type Int32 binds to "MCForeignIntTypeInfo"
2727

28-
public foreign type UIntSize binds to "kMCSizeTypeInfo"
29-
public foreign type IntSize binds to "kMCSSizeTypeInfo"
28+
public foreign type UIntSize binds to "MCForeignSizeTypeInfo"
29+
public foreign type IntSize binds to "MCForeignSSizeTypeInfo"
3030

31-
public foreign type Float32 binds to "kMCFloatTypeInfo"
32-
public foreign type Float64 binds to "kMCDoubleTypeInfo"
31+
public foreign type Float32 binds to "MCForeignFloatTypeInfo"
32+
public foreign type Float64 binds to "MCForeignDoubleTypeInfo"
3333

3434
----------------------------------------------------------------
3535
-- C types
3636
----------------------------------------------------------------
3737

38-
public foreign type CBool binds to "kMCBoolTypeInfo"
38+
public foreign type CBool binds to "MCForeignBoolTypeInfo"
3939
public type CInt is Int32
4040
public type CUInt is UInt32
4141
public type CFloat is Float32
@@ -54,7 +54,7 @@ public type LCUIndex is UInt32
5454
-- Nul-terminated string pointer types
5555
----------------------------------------------------------------
5656

57-
public foreign type ZStringNative binds to "kMCNativeCStringTypeInfo"
58-
public foreign type ZStringUTF16 binds to "kMCWStringTypeInfo"
57+
public foreign type ZStringNative binds to "MCNativeCStringTypeInfo"
58+
public foreign type ZStringUTF16 binds to "MCWStringTypeInfo"
5959

6060
end module

libscript/src/module-foreign.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222

2323
////////////////////////////////////////////////////////////////////////////////
2424

25-
extern "C"
26-
{
27-
MC_DLLEXPORT_DEF MCTypeInfoRef kMCNativeCStringTypeInfo;
28-
MC_DLLEXPORT_DEF MCTypeInfoRef kMCWStringTypeInfo;
29-
}
25+
MCTypeInfoRef kMCNativeCStringTypeInfo;
26+
MCTypeInfoRef kMCWStringTypeInfo;
27+
28+
extern "C" MC_DLLEXPORT_DEF MCTypeInfoRef MCNativeCStringTypeInfo(void) { return kMCNativeCStringTypeInfo; }
29+
extern "C" MC_DLLEXPORT_DEF MCTypeInfoRef MCWStringTypeInfo(void) { return kMCWStringTypeInfo; }
3030

3131
MCTypeInfoRef kMCForeignZStringNullErrorTypeInfo;
3232

libscript/src/script-module.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,8 +752,10 @@ bool MCScriptEnsureModuleIsUsable(MCScriptModuleRef self)
752752
nil);
753753
goto error_cleanup;
754754
}
755-
756-
t_typeinfo = MCValueRetain(*(MCTypeInfoRef *)t_symbol);
755+
756+
/* The symbol is a function that returns a type info reference. */
757+
MCTypeInfoRef (*t_type_func)(void) = (MCTypeInfoRef (*)(void)) t_symbol;
758+
t_typeinfo = MCValueRetain(t_type_func());
757759
}
758760
break;
759761
case kMCScriptTypeKindRecord:

libscript/src/script-object.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,79 +91,79 @@ bool MCScriptInitialize(void)
9191
uindex_t t_def_index, t_type_index;
9292

9393
MCScriptAddDefinitionToModule(t_builder, t_def_index);
94-
MCScriptAddForeignTypeToModule(t_builder, MCSTR("kMCAnyTypeInfo"), t_type_index);
94+
MCScriptAddForeignTypeToModule(t_builder, MCSTR("MCAnyTypeInfo"), t_type_index);
9595
MCScriptAddTypeToModule(t_builder, MCNAME("any"), t_type_index, t_def_index);
9696
MCScriptAddExportToModule(t_builder, t_def_index);
9797

9898
uindex_t t_null_type_index;
9999
MCScriptAddDefinitionToModule(t_builder, t_null_type_index);
100-
MCScriptAddForeignTypeToModule(t_builder, MCSTR("kMCNullTypeInfo"), t_type_index);
100+
MCScriptAddForeignTypeToModule(t_builder, MCSTR("MCNullTypeInfo"), t_type_index);
101101
MCScriptAddTypeToModule(t_builder, MCNAME("undefined"), t_type_index, t_null_type_index);
102102
MCScriptAddExportToModule(t_builder, t_null_type_index);
103103

104104
MCScriptAddDefinitionToModule(t_builder, t_def_index);
105-
MCScriptAddForeignTypeToModule(t_builder, MCSTR("kMCBooleanTypeInfo"), t_type_index);
105+
MCScriptAddForeignTypeToModule(t_builder, MCSTR("MCBooleanTypeInfo"), t_type_index);
106106
MCScriptAddTypeToModule(t_builder, MCNAME("boolean"), t_type_index, t_def_index);
107107
MCScriptAddExportToModule(t_builder, t_def_index);
108108

109109
MCScriptAddDefinitionToModule(t_builder, t_def_index);
110-
MCScriptAddForeignTypeToModule(t_builder, MCSTR("kMCNumberTypeInfo"), t_type_index);
110+
MCScriptAddForeignTypeToModule(t_builder, MCSTR("MCNumberTypeInfo"), t_type_index);
111111
MCScriptAddTypeToModule(t_builder, MCNAME("number"), t_type_index, t_def_index);
112112
MCScriptAddExportToModule(t_builder, t_def_index);
113113

114114
uindex_t t_string_type_index;
115115
MCScriptAddDefinitionToModule(t_builder, t_string_type_index);
116-
MCScriptAddForeignTypeToModule(t_builder, MCSTR("kMCStringTypeInfo"), t_type_index);
116+
MCScriptAddForeignTypeToModule(t_builder, MCSTR("MCStringTypeInfo"), t_type_index);
117117
MCScriptAddTypeToModule(t_builder, MCNAME("string"), t_type_index, t_string_type_index);
118118
MCScriptAddExportToModule(t_builder, t_string_type_index);
119119

120120
MCScriptAddDefinitionToModule(t_builder, t_def_index);
121-
MCScriptAddForeignTypeToModule(t_builder, MCSTR("kMCDataTypeInfo"), t_type_index);
121+
MCScriptAddForeignTypeToModule(t_builder, MCSTR("MCDataTypeInfo"), t_type_index);
122122
MCScriptAddTypeToModule(t_builder, MCNAME("data"), t_type_index, t_def_index);
123123
MCScriptAddExportToModule(t_builder, t_def_index);
124124

125125
MCScriptAddDefinitionToModule(t_builder, t_def_index);
126-
MCScriptAddForeignTypeToModule(t_builder, MCSTR("kMCArrayTypeInfo"), t_type_index);
126+
MCScriptAddForeignTypeToModule(t_builder, MCSTR("MCArrayTypeInfo"), t_type_index);
127127
MCScriptAddTypeToModule(t_builder, MCNAME("array"), t_type_index, t_def_index);
128128
MCScriptAddExportToModule(t_builder, t_def_index);
129129

130130
MCScriptAddDefinitionToModule(t_builder, t_def_index);
131-
MCScriptAddForeignTypeToModule(t_builder, MCSTR("kMCProperListTypeInfo"), t_type_index);
131+
MCScriptAddForeignTypeToModule(t_builder, MCSTR("MCProperListTypeInfo"), t_type_index);
132132
MCScriptAddTypeToModule(t_builder, MCNAME("list"), t_type_index, t_def_index);
133133
MCScriptAddExportToModule(t_builder, t_def_index);
134134

135135
////
136136

137137
uindex_t t_bool_type_index;
138138
MCScriptAddDefinitionToModule(t_builder, t_bool_type_index);
139-
MCScriptAddForeignTypeToModule(t_builder, MCSTR("kMCBoolTypeInfo"), t_type_index);
139+
MCScriptAddForeignTypeToModule(t_builder, MCSTR("MCForeignBoolTypeInfo"), t_type_index);
140140
MCScriptAddTypeToModule(t_builder, MCNAME("bool"), t_type_index, t_bool_type_index);
141141
MCScriptAddExportToModule(t_builder, t_bool_type_index);
142142

143143
MCScriptAddDefinitionToModule(t_builder, t_def_index);
144-
MCScriptAddForeignTypeToModule(t_builder, MCSTR("kMCIntTypeInfo"), t_type_index);
144+
MCScriptAddForeignTypeToModule(t_builder, MCSTR("MCForeignIntTypeInfo"), t_type_index);
145145
MCScriptAddTypeToModule(t_builder, MCNAME("int"), t_type_index, t_def_index);
146146
MCScriptAddExportToModule(t_builder, t_def_index);
147147

148148
uindex_t t_uint_type_index;
149149
MCScriptAddDefinitionToModule(t_builder, t_uint_type_index);
150-
MCScriptAddForeignTypeToModule(t_builder, MCSTR("kMCUIntTypeInfo"), t_type_index);
150+
MCScriptAddForeignTypeToModule(t_builder, MCSTR("MCForeignUIntTypeInfo"), t_type_index);
151151
MCScriptAddTypeToModule(t_builder, MCNAME("uint"), t_type_index, t_uint_type_index);
152152
MCScriptAddExportToModule(t_builder, t_uint_type_index);
153153

154154
MCScriptAddDefinitionToModule(t_builder, t_def_index);
155-
MCScriptAddForeignTypeToModule(t_builder, MCSTR("kMCFloatTypeInfo"), t_type_index);
155+
MCScriptAddForeignTypeToModule(t_builder, MCSTR("MCForeignFloatTypeInfo"), t_type_index);
156156
MCScriptAddTypeToModule(t_builder, MCNAME("float"), t_type_index, t_def_index);
157157
MCScriptAddExportToModule(t_builder, t_def_index);
158158

159159
uindex_t t_double_type_index;
160160
MCScriptAddDefinitionToModule(t_builder, t_double_type_index);
161-
MCScriptAddForeignTypeToModule(t_builder, MCSTR("kMCDoubleTypeInfo"), t_type_index);
161+
MCScriptAddForeignTypeToModule(t_builder, MCSTR("MCForeignDoubleTypeInfo"), t_type_index);
162162
MCScriptAddTypeToModule(t_builder, MCNAME("double"), t_type_index, t_double_type_index);
163163
MCScriptAddExportToModule(t_builder, t_double_type_index);
164164

165165
MCScriptAddDefinitionToModule(t_builder, t_def_index);
166-
MCScriptAddForeignTypeToModule(t_builder, MCSTR("kMCPointerTypeInfo"), t_type_index);
166+
MCScriptAddForeignTypeToModule(t_builder, MCSTR("MCForeignPointerTypeInfo"), t_type_index);
167167
MCScriptAddTypeToModule(t_builder, MCNAME("pointer"), t_type_index, t_def_index);
168168
MCScriptAddExportToModule(t_builder, t_def_index);
169169

libscript/src/stream.mlc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ stream input and output operations in modular LiveCode.
2222

2323
module com.livecode.stream
2424

25-
public foreign type Stream binds to "kMCStreamTypeInfo"
25+
public foreign type Stream binds to "MCStreamTypeInfo"
2626

2727
--
2828

0 commit comments

Comments
 (0)