Skip to content

Commit 4ee24ec

Browse files
[[ ExternalsV6 ]] Update UTF16 data to carry the number of chars, not bytes. Updated externals test
1 parent 1c04b45 commit 4ee24ec

File tree

12 files changed

+187
-17
lines changed

12 files changed

+187
-17
lines changed

engine/engine-mobile.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@
655655
4DA2CA351136D07600B9F27B /* eventqueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = eventqueue.cpp; path = src/eventqueue.cpp; sourceTree = "<group>"; };
656656
4DA2CA371136D08700B9F27B /* eventqueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = eventqueue.h; path = src/eventqueue.h; sourceTree = "<group>"; };
657657
4DA2CA381136D08700B9F27B /* externalv0.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = externalv0.cpp; path = src/externalv0.cpp; sourceTree = "<group>"; };
658-
4DA2CA391136D08700B9F27B /* externalv1.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = externalv1.cpp; path = src/externalv1.cpp; sourceTree = "<group>"; };
658+
4DA2CA391136D08700B9F27B /* externalv1.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; name = externalv1.cpp; path = src/externalv1.cpp; sourceTree = "<group>"; };
659659
4DA2CA3D1136D0A800B9F27B /* notify.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = notify.cpp; path = src/notify.cpp; sourceTree = "<group>"; };
660660
4DA2CA3E1136D0A800B9F27B /* notify.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = notify.h; path = src/notify.h; sourceTree = "<group>"; };
661661
4DA7BA391324E50300F9214A /* mbliphoneinput.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = mbliphoneinput.mm; path = src/mbliphoneinput.mm; sourceTree = "<group>"; };

engine/src/externalv1.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,6 +1790,8 @@ static MCExternalError MCExternalVariableStore(MCExternalVariableRef var, MCExte
17901790
{
17911791
MCAutoStringRef t_stringref;
17921792

1793+
char* t_string = *(char**)p_value;
1794+
17931795
if (!MCStringCreateWithBytes(*(byte_t**)p_value, strlen(*(char**)p_value), kMCStringEncodingUTF8, false, &t_stringref))
17941796
return kMCExternalErrorOutOfMemory;
17951797

@@ -1799,8 +1801,8 @@ static MCExternalError MCExternalVariableStore(MCExternalVariableRef var, MCExte
17991801
{
18001802
MCAutoStringRef t_stringref;
18011803
MCString* t_string;
1802-
t_string = (MCString*)t_string;
1803-
if (!MCStringCreateWithBytes((byte_t*)t_string->getstring(), t_string->getlength(), kMCStringEncodingUTF16, false, &t_stringref))
1804+
t_string = (MCString*)p_value;
1805+
if (!MCStringCreateWithBytes((byte_t*)t_string->getstring(), 2 * t_string->getlength(), kMCStringEncodingUTF16, false, &t_stringref))
18041806
return kMCExternalErrorOutOfMemory;
18051807

18061808
return var -> SetString(*t_stringref);
@@ -1815,6 +1817,7 @@ static MCExternalError MCExternalVariableStore(MCExternalVariableRef var, MCExte
18151817
for (t_char_count = 0 ; *t_chars; ++t_char_count)
18161818
++t_chars;
18171819

1820+
18181821
if (!MCStringCreateWithChars(*(const unichar_t**)p_value, t_char_count, &t_stringref))
18191822
return kMCExternalErrorOutOfMemory;
18201823

@@ -1988,7 +1991,7 @@ static MCExternalError MCExternalVariableFetch(MCExternalVariableRef var, MCExte
19881991
if (!MCStringConvertToUnicode(*t_stringref, t_chars, t_char_count))
19891992
return kMCExternalErrorOutOfMemory;
19901993

1991-
((MCString*)p_value) -> set((char*)t_chars, t_char_count * 2);
1994+
((MCString*)p_value) -> set((char*)t_chars, t_char_count);
19921995
break;
19931996
}
19941997
case kMCExternalValueOptionAsUTF16CString:
@@ -2166,7 +2169,7 @@ static MCExternalError MCExternalVariableAppend(MCExternalVariableRef var, MCExt
21662169
MCAutoStringRef t_stringref;
21672170
MCString* t_string;
21682171
t_string = (MCString*)t_string;
2169-
if (!MCStringCreateWithBytes((byte_t*)t_string->getstring(), t_string->getlength(), kMCStringEncodingUTF16, false, &t_stringref))
2172+
if (!MCStringCreateWithBytes((byte_t*)t_string->getstring(), 2 * t_string->getlength(), kMCStringEncodingUTF16, false, &t_stringref))
21702173
return kMCExternalErrorOutOfMemory;
21712174

21722175
return var -> AppendString(p_options, *t_stringref);
4.3 KB
Binary file not shown.

revtestexternal/revtestexternal-mobile.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
isa = PBXContainerItemProxy;
3333
containerPortal = 4D16889117AFE4160068A5C5 /* lcidlc.xcodeproj */;
3434
proxyType = 2;
35-
remoteGlobalIDString = 4D57DF461338F14B0044FFEC /* lcidlc */;
35+
remoteGlobalIDString = 4D57DF461338F14B0044FFEC;
3636
remoteInfo = lcidlc;
3737
};
3838
/* End PBXContainerItemProxy section */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

revtestexternal/revtestexternal.lcidl

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,43 +33,44 @@ command revTestExternalTestWait
3333

3434
command revTestExternalTestArrays
3535

36-
command revTextExternalTestUTF8String
36+
function revTestExternalTestUTF8String
3737
in string as utf8-c-string
3838
return utf8-c-string
3939

40-
command revTestExternalTestUTF16String
40+
function revTestExternalTestUTF16String
4141
in string as utf16-c-string
4242
return utf16-c-string
4343

44-
command revTestExternalTestUTF8Data
44+
function revTestExternalTestUTF8Data
4545
in data as utf8-c-data
4646
return utf8-c-data
4747

48-
command revTestExternalTestUTF16Data
48+
function revTestExternalTestUTF16Data
4949
in data as utf16-c-data
5050
return utf16-c-data
5151

5252
use java on android
53+
use none on linux,mac,windows,ios
5354
command revTestExternalTestPostAndSend
5455

5556
use none on linux, windows, android
5657
use objc on mac, ios
5758

58-
/*command revTestExternalTestObjcArrays
59+
function revTestExternalTestObjcArrays
5960
in array as objc-array
6061
return objc-array
6162

62-
command revTestExternalTestObjcDictionaries
63+
function revTestExternalTestObjcDictionaries
6364
in dict as objc-dictionary
6465
return objc-dictionary
6566

66-
command revtestExternalTestObjcNumber
67+
function revtestExternalTestObjcNumber
6768
in number as objc-number
6869
return objc-number
6970

70-
command revTestExternalTestObbjcData
71+
function revTestExternalTestObbjcData
7172
in data as objc-data
72-
return objc-data*/
73+
return objc-data
7374

7475
use none on mac, linux, windows, android, ios
7576
use java on android
@@ -79,4 +80,20 @@ tail command revTestExternalAndroidButtonDestroy
7980

8081
function revTestExternalRunActivity return c-string
8182

83+
function revTestExternalTestAndroidUTF8String
84+
in string as utf8-c-string
85+
return utf8-c-string
86+
87+
function revTestExternalTestAndroidUTF16String
88+
in string as utf16-c-string
89+
return utf16-c-string
90+
91+
function revTestExternalTestAndroidUTF8Data
92+
in data as utf8-c-data
93+
return utf8-c-data
94+
95+
function revTestExternalTestAndroidUTF16Data
96+
in data as utf16-c-data
97+
return utf16-c-data
98+
8299
command revTestExternalRunOnSystemThread
1.55 KB
Binary file not shown.

revtestexternal/revtestexternal.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
4DCD722A176B47E00033F2AB /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4DCD7229176B47E00033F2AB /* Foundation.framework */; };
1212
4DCD722D176B47E40033F2AB /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4DCD7229176B47E00033F2AB /* Foundation.framework */; };
1313
4DCD72BE176B48B40033F2AB /* revtestexternal.lcidl in Sources */ = {isa = PBXBuildFile; fileRef = 4D40528E176B3EF10097F2D6 /* revtestexternal.lcidl */; };
14+
BEB1BDAF1977C7D60017E28B /* revtestexternal.mm in Sources */ = {isa = PBXBuildFile; fileRef = BEB1BDAE1977C7D60017E28B /* revtestexternal.mm */; };
1415
E82D44EE17131E7700A10289 /* revtestexternal.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E82D44ED17131E7700A10289 /* revtestexternal.cpp */; };
1516
E82D458F1713237A00A10289 /* revtestexternal.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E82D44ED17131E7700A10289 /* revtestexternal.cpp */; };
1617
/* End PBXBuildFile section */
@@ -133,6 +134,7 @@
133134
4D405323176B3FC50097F2D6 /* lcidlc.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = lcidlc.xcodeproj; path = ../lcidlc/lcidlc.xcodeproj; sourceTree = SOURCE_ROOT; };
134135
4D40532D176B3FCE0097F2D6 /* engine.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = engine.xcodeproj; path = ../engine/engine.xcodeproj; sourceTree = SOURCE_ROOT; };
135136
4DCD7229176B47E00033F2AB /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
137+
BEB1BDAE1977C7D60017E28B /* revtestexternal.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = revtestexternal.mm; path = src/revtestexternal.mm; sourceTree = "<group>"; };
136138
E82D44D717131C3400A10289 /* revtestexternal.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = revtestexternal.bundle; sourceTree = BUILT_PRODUCTS_DIR; };
137139
E82D44E917131D7500A10289 /* Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = ../rules/Debug.xcconfig; sourceTree = "<group>"; };
138140
E82D44EA17131D7500A10289 /* Global.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Global.xcconfig; path = ../rules/Global.xcconfig; sourceTree = "<group>"; };
@@ -230,6 +232,7 @@
230232
E82D44EC17131E6800A10289 /* Sources */ = {
231233
isa = PBXGroup;
232234
children = (
235+
BEB1BDAE1977C7D60017E28B /* revtestexternal.mm */,
233236
4D332C95178D7BDF005DFE92 /* revtestexternal.java */,
234237
4D40528E176B3EF10097F2D6 /* revtestexternal.lcidl */,
235238
E82D44ED17131E7700A10289 /* revtestexternal.cpp */,
@@ -431,6 +434,7 @@
431434
files = (
432435
4D405352176B40B70097F2D6 /* revtestexternal.lcidl in Sources */,
433436
E82D44EE17131E7700A10289 /* revtestexternal.cpp in Sources */,
437+
BEB1BDAF1977C7D60017E28B /* revtestexternal.mm in Sources */,
434438
);
435439
runOnlyForDeploymentPostprocessing = 0;
436440
};

revtestexternal/src/revtestexternal.cpp

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
#include <cstdio>
1818
#include <cstdarg>
19+
#include <stdint.h>
20+
#include <cstring>
21+
#include <cstdlib>
1922

2023
#include <LiveCode.h>
2124

@@ -122,28 +125,93 @@ void revTestExternalTestWait(void)
122125
LCContextExecute("answer \"Done!\"", 0);
123126
}
124127

128+
void write_utf8_clef(char* t_string)
129+
{
130+
t_string[0] = 0xF0;
131+
t_string[1] = 0x9D;
132+
t_string[2] = 0x84;
133+
t_string[3] = 0x9E;
134+
}
135+
136+
void write_utf16_clef(uint16_t* t_string)
137+
{
138+
t_string[0] = 0xD834;
139+
t_string[1] = 0xDD1E;
140+
}
141+
142+
int measure_utf16(uint16_t* string)
143+
{
144+
uint32_t t_size = 0;
145+
146+
while (*string != 0)
147+
string++, t_size++;
148+
149+
return t_size;
150+
}
125151

126152
void revTestExternalTestArrays(void)
127153
{
128154
}
129155

130-
char* revTextExternalTestUTF8String(const char* string)
156+
char* revTestExternalTestUTF8String(const char* string)
131157
{
158+
uint32_t t_length;
159+
160+
t_length = strlen(string);
161+
fprintf(stderr, "%hhX%hhX%hhX", string[0], string[1], string[2]);
162+
163+
char* t_out = (char*)malloc(t_length + 9);
164+
165+
write_utf8_clef(t_out);
166+
memcpy(t_out + 4, string, t_length);
167+
write_utf8_clef(t_out + 4 + t_length);
168+
t_out[t_length + 8] = '\0';
169+
170+
return t_out;
132171
}
133172

134173
char* revTestExternalTestUTF16String(const char* string)
135174
{
175+
uint32_t t_length;
176+
177+
t_length = measure_utf16((uint16_t*)string);
136178

179+
uint16_t* t_out = (uint16_t*)malloc(2 * (t_length + 5));
180+
181+
write_utf16_clef(t_out);
182+
memcpy(t_out + 2, string, 2 * t_length);
183+
write_utf16_clef(t_out + 2 + t_length);
184+
t_out[t_length + 4] = '\0';
185+
186+
return (char*)t_out;
137187
}
138188

139189
LCBytes revTestExternalTestUTF8Data(LCBytes data)
140190
{
191+
LCBytes t_out;
192+
t_out.buffer = malloc(data.length + 9);
193+
194+
write_utf8_clef((char*)t_out.buffer);
195+
memcpy(((char*)t_out.buffer) + 4, data.buffer, data.length);
196+
write_utf8_clef(((char*)t_out.buffer) + 4 + data.length);
197+
((char*)t_out.buffer)[data.length + 8] = '\0';
198+
t_out.length = data.length + 8;
141199

200+
return t_out;
142201
}
143202

144203
LCBytes revTestExternalTestUTF16Data(LCBytes data)
145-
{
204+
{
205+
LCBytes t_out;
206+
t_out.buffer = malloc(2 * (data.length + 5));
207+
208+
write_utf16_clef((uint16_t*)t_out.buffer);
209+
memcpy(((uint16_t*)t_out.buffer) + 2, data.buffer, 2 * data.length);
210+
write_utf16_clef(((uint16_t*)t_out.buffer) + 2 + data.length);
211+
((uint16_t*)t_out.buffer)[data.length + 4] = '\0';
212+
t_out.length = data.length + 4;
146213

214+
return t_out;
147215
}
148216
/*
149217
command revTestExternalTestObjcArrays

revtestexternal/src/revtestexternal.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import android.widget.*;
99
import android.content.*;
1010
import android.net.*;
11+
import java.lang.String;
12+
import java.io.UnsupportedEncodingException;
1113

1214
// We must export a public class with the same name as the external.
1315
public class revtestexternal
@@ -17,6 +19,12 @@ public class revtestexternal
1719

1820
// The LC object to send the pressed message to.
1921
static LC.Object s_target;
22+
23+
// Treble UTF-8 clef
24+
char[] m_utf8_clef = null;
25+
26+
// Treble UTF-16 clef
27+
short[] m_utf16_clef = null;
2028

2129
public static void revTestExternalAndroidButtonCreate()
2230
{
@@ -106,6 +114,48 @@ public void onCancel(DialogInterface p_dialog)
106114

107115
t_wait . Release();
108116
}
117+
118+
private static String trebleClef()
119+
{
120+
byte[] t_utf8_clef = new byte[4];
121+
t_utf8_clef[0] = Integer.decode("0xF0").byteValue();
122+
t_utf8_clef[1] = Integer.decode("0x9D").byteValue();
123+
t_utf8_clef[2] = Integer.decode("0x84").byteValue();
124+
t_utf8_clef[3] = Integer.decode("0x9E").byteValue();
125+
126+
try
127+
{
128+
return new String(t_utf8_clef, "UTF8");
129+
}
130+
catch(UnsupportedEncodingException e)
131+
{
132+
return null;
133+
}
134+
}
135+
136+
public static String revTestExternalTestAndroidUTF8String(String p_string)
137+
{
138+
String t_string = new String();
139+
return t_string . concat(trebleClef()) . concat(p_string) . concat(trebleClef());
140+
}
141+
142+
public static String revTestExternalTestAndroidUTF16String(String p_string)
143+
{
144+
String t_string = new String();
145+
return t_string . concat(trebleClef()) . concat(p_string) . concat(trebleClef());
146+
}
147+
148+
public static String revTestExternalTestAndroidUTF8Data(String p_string)
149+
{
150+
String t_string = new String();
151+
return t_string . concat(trebleClef()) . concat(p_string) . concat(trebleClef());
152+
}
153+
154+
public static String revTestExternalTestAndroidUTF16Data(String p_string)
155+
{
156+
String t_string = new String();
157+
return t_string . concat(trebleClef()) . concat(p_string) . concat(trebleClef());
158+
}
109159

110160
public static void revTestExternalTestPostAndSend()
111161
{

0 commit comments

Comments
 (0)