Skip to content

Commit 7ddb22e

Browse files
committed
Merge branch 'feature/lcidl_parameters' of https://github.com/montegoulding/livecode into feature-externals_api_v5
2 parents f13d36b + c477700 commit 7ddb22e

12 files changed

Lines changed: 543 additions & 325 deletions

lcidlc/lclink.sh

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ if [ "$LIVECODE_DEP_FILE" == "" ]; then
55
fi
66

77
DEPS=`cat "$LIVECODE_DEP_FILE"`
8+
9+
SDK_MAJORVERSION=${SDK_NAME: -3}
10+
SDK_MAJORVERSION=${SDK_MAJORVERSION: 0:1}
11+
SDK_MINORVERSION=${SDK_NAME: -1}
12+
13+
# Frameworks may not exist in older sdks so conditionally include
14+
for MAJORVERSION in 3 4 5 6 7; do
15+
for MINORVERSION in 0 1 2 3 4; do
16+
if [[ $SDK_MAJORVERSION -lt $MAJORVERSION || ($SDK_MAJORVERSION == $MAJORVERSION && $SDK_MINORVERSION -lt $MINORVERSION) ]]; then
17+
DEPS="$(echo "$DEPS" | sed "/framework-$MAJORVERSION.$MINORVERSION /d")"
18+
DEPS="$(echo "$DEPS" | sed "/weak-framework-$MAJORVERSION.$MINORVERSION /d")"
19+
else
20+
DEPS=${DEPS//framework-$MAJORVERSION.$MINORVERSION /framework }
21+
DEPS=${DEPS//weak-framework-$MAJORVERSION.$MINORVERSION /weak-framework }
22+
fi
23+
done
24+
done
25+
826
DEPS=${DEPS//library /-l}
927
DEPS=${DEPS//weak-framework /-weak }
1028
DEPS=${DEPS//framework /-framework }
@@ -16,8 +34,11 @@ echo $DEPS
1634
# used - thus we force linking to Foundation, dittor for UIKit
1735
DEPS="$DEPS -framework Foundation -framework UIKit"
1836

19-
# The list of symbols exported by an iOS external is fixed
20-
SYMBOLS="_MCExternalDescribe _MCExternalInitialize _MCExternalFinalize"
37+
# Support using the same script for old externals
38+
if [ "$SYMBOLS" != "_getXtable" ]; then
39+
# The list of symbols exported by an iOS external is fixed
40+
SYMBOLS="_MCExternalDescribe _MCExternalInitialize _MCExternalFinalize"
41+
fi
2142

2243
# Munge the passed in ARCHS environment variable into a form suitable for g++
2344
ARCHS="-arch ${ARCHS// / -arch }"

lcidlc/src/Interface.cpp

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
1919

2020
#include "Interface.h"
2121
#include "InterfacePrivate.h"
22+
#include "NativeType.h"
2223

2324
////////////////////////////////////////////////////////////////////////////////
2425

@@ -38,7 +39,8 @@ enum InterfaceError
3839
kInterfaceErrorParamAlreadyDefined,
3940
kInterfaceErrorInvalidParameterType,
4041
kInterfaceErrorOptionalParamImpliesIn,
41-
kInterfaceErrorNoOptionalBoolean,
42+
kInterfaceErrorNonPointerOptionalParameterMustHaveDefaultValue,
43+
kInterfaceErrorDefaultWrongType,
4244
kInterfaceErrorUnknownType,
4345
kInterfaceErrorJavaImpliesInParam,
4446
kInterfaceErrorMethodsCannotHaveVariants,
@@ -120,8 +122,11 @@ static bool InterfaceReport(InterfaceRef self, Position p_where, InterfaceError
120122
case kInterfaceErrorOptionalParamImpliesIn:
121123
fprintf(stderr, "Optional parameters must be of 'in' type\n");
122124
break;
123-
case kInterfaceErrorNoOptionalBoolean:
124-
fprintf(stderr, "Optional boolean parameters not yet supported\n");
125+
case kInterfaceErrorNonPointerOptionalParameterMustHaveDefaultValue:
126+
fprintf(stderr, "Default values must be specified for non-pointer type optional parameters\n");
127+
break;
128+
case kInterfaceErrorDefaultWrongType:
129+
fprintf(stderr, "Default specified is the wrong type\n");
125130
break;
126131
case kInterfaceErrorUnknownType:
127132
fprintf(stderr, "Unknown type '%s'\n", StringGetCStringPtr(NameGetString((NameRef)p_hint)));
@@ -406,11 +411,11 @@ bool InterfaceEndHandler(InterfaceRef self)
406411
return true;
407412
}
408413

409-
bool InterfaceDefineHandlerParameter(InterfaceRef self, Position p_where, ParameterType p_param_type, NameRef p_name, NameRef p_type, ValueRef p_default)
414+
bool InterfaceDefineHandlerParameter(InterfaceRef self, Position p_where, ParameterType p_param_type, NameRef p_name, NameRef p_type, ValueRef p_default, bool p_optional)
410415
{
411416
static const char *s_param_types[] = {"in", "out", "inout", "ref"};
412417
MCLog("%s - %s%s parameter %s as %s", PositionDescribe(p_where),
413-
p_default != nil ? "optional " : "",
418+
p_optional ? "optional " : "",
414419
s_param_types[p_param_type],
415420
StringGetCStringPtr(NameGetString(p_name)),
416421
StringGetCStringPtr(NameGetString(p_type)));
@@ -424,11 +429,46 @@ bool InterfaceDefineHandlerParameter(InterfaceRef self, Position p_where, Parame
424429
// RULE: 'ref' not currently supported
425430
if (p_param_type == kParameterTypeRef)
426431
InterfaceReport(self, p_where, kInterfaceErrorInvalidParameterType, nil);
427-
428-
// RULE: optional 'boolean' not currently supported
429-
if (NameEqualToCString(p_type, "boolean") && p_default != nil)
430-
InterfaceReport(self, p_where, kInterfaceErrorNoOptionalBoolean, nil);
431-
432+
433+
// RULE: only pointer types may not have a default value
434+
if (p_optional && p_default == nil &&
435+
(NameEqualToCString(p_type, "boolean") ||
436+
NameEqualToCString(p_type, "integer") ||
437+
NameEqualToCString(p_type, "real") ||
438+
NameEqualToCString(p_type, "c-data")))
439+
InterfaceReport(self, p_where, kInterfaceErrorNonPointerOptionalParameterMustHaveDefaultValue, nil);
440+
441+
NativeType t_native_type;
442+
t_native_type = NativeTypeFromName(p_type);
443+
444+
// RULE: wrong default type
445+
if (p_default != nil)
446+
{
447+
bool t_correct_type = false;
448+
switch (t_native_type) {
449+
case kNativeTypeBoolean:
450+
t_correct_type = ValueIsBoolean(p_default);
451+
break;
452+
case kNativeTypeInteger:
453+
t_correct_type = ValueIsInteger(p_default);
454+
break;
455+
case kNativeTypeReal:
456+
t_correct_type = ValueIsReal(p_default) || ValueIsInteger(p_default);
457+
break;
458+
case kNativeTypeObjcString:
459+
case kNativeTypeCString:
460+
case kNativeTypeEnum:
461+
t_correct_type = ValueIsString(p_default);
462+
break;
463+
default:
464+
t_correct_type = false;
465+
break;
466+
}
467+
468+
if (!t_correct_type)
469+
InterfaceReport(self, p_where, kInterfaceErrorDefaultWrongType, nil);
470+
}
471+
432472
// RULE: optional parameters can only be 'in'
433473
if (p_default != nil && p_param_type != kParameterTypeIn)
434474
InterfaceReport(self, p_where, kInterfaceErrorOptionalParamImpliesIn, nil);
@@ -442,9 +482,9 @@ bool InterfaceDefineHandlerParameter(InterfaceRef self, Position p_where, Parame
442482
}
443483

444484
// RULE: No non-optional parameters after an optional one
445-
if (p_default == nil &&
485+
if (!p_optional &&
446486
t_variant -> parameter_count > 0 &&
447-
t_variant -> parameters[t_variant -> parameter_count - 1] . default_value != nil)
487+
t_variant -> parameters[t_variant -> parameter_count - 1] . is_optional)
448488
InterfaceReport(self, p_where, kInterfaceErrorParamAfterOptionalParam, nil);
449489

450490
// RULE: If java handler, then only in parameters are allowed.
@@ -460,8 +500,9 @@ bool InterfaceDefineHandlerParameter(InterfaceRef self, Position p_where, Parame
460500
t_variant -> parameters[t_variant -> parameter_count - 1] . name = ValueRetain(p_name);
461501
t_variant -> parameters[t_variant -> parameter_count - 1] . type = ValueRetain(p_type);
462502
t_variant -> parameters[t_variant -> parameter_count - 1] . default_value = ValueRetain(p_default);
503+
t_variant -> parameters[t_variant -> parameter_count - 1] . is_optional = p_optional;
463504

464-
if (p_default == nil)
505+
if (!p_optional)
465506
t_variant -> minimum_parameter_count += 1;
466507

467508
return true;

lcidlc/src/Interface.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ bool InterfaceBeginEnum(InterfaceRef interface, Position where, NameRef name);
6060
bool InterfaceDefineEnumElement(InterfaceRef interface, Position where, StringRef element, ValueRef value);
6161
bool InterfaceEndEnum(InterfaceRef interface);
6262

63-
bool InterfaceBeginHandler(InterfaceRef interface, Position where, HandlerType type, HandlerAttributes attrs, NameRef name);
64-
bool InterfaceDefineHandlerParameter(InterfaceRef interface, Position where, ParameterType param_type, NameRef name, NameRef type, ValueRef default_value);
63+
bool InterfaceBeginHandler(InterfaceRef interface, Position where, HandlerType type, HandlerAttributes attr, NameRef name);
64+
bool InterfaceDefineHandlerParameter(InterfaceRef interface, Position where, ParameterType param_type, NameRef name, NameRef type, ValueRef default_value, bool p_optional);
6565
bool InterfaceDefineHandlerReturn(InterfaceRef interface, Position where, NameRef type, bool indirect);
6666
bool InterfaceDefineHandlerBinding(InterfaceRef interface, Position where, NameRef name);
6767
bool InterfaceEndHandler(InterfaceRef interface);

0 commit comments

Comments
 (0)