- Optimization: common parameters to built in functions are no longer looked up as a string at each call, instead their integer ids are global constants

- Optimization: some other minor tweaks.
 - Nicer --help message

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@783 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-12-24 02:04:45 +00:00
parent b79f52db84
commit 547a48b98d
23 changed files with 232 additions and 134 deletions
+48 -45
View File
@@ -21,9 +21,12 @@ DECLARE_TYPEOF_COLLECTION(pair<String COMMA ScriptValueP>);
// ----------------------------------------------------------------------------- : Debugging
SCRIPT_FUNCTION(trace) {
SCRIPT_PARAM(String, input);
//handle_warning(_("Trace:\t") + input, false);
wxLogDebug(_("Trace:\t") + input);
SCRIPT_PARAM_C(String, input);
#ifdef _DEBUG
wxLogDebug(_("Trace:\t") + input);
#else
handle_warning(_("Trace:\t") + input, false);
#endif
SCRIPT_RETURN(input);
}
@@ -31,38 +34,38 @@ SCRIPT_FUNCTION(trace) {
// convert a string to upper case
SCRIPT_FUNCTION(to_upper) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
SCRIPT_RETURN(input.Upper());
}
// convert a string to lower case
SCRIPT_FUNCTION(to_lower) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
SCRIPT_RETURN(input.Lower());
}
// convert a string to title case
SCRIPT_FUNCTION(to_title) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
SCRIPT_RETURN(capitalize(input));
}
// reverse a string
SCRIPT_FUNCTION(reverse) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
reverse(input.begin(), input.end());
SCRIPT_RETURN(input);
}
// remove leading and trailing whitespace from a string
SCRIPT_FUNCTION(trim) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
SCRIPT_RETURN(trim(input));
}
// extract a substring
SCRIPT_FUNCTION(substring) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
SCRIPT_PARAM_DEFAULT(int, begin, 0);
SCRIPT_PARAM_DEFAULT(int, end, INT_MAX);
if (begin < 0) begin = 0;
@@ -78,22 +81,22 @@ SCRIPT_FUNCTION(substring) {
// does a string contain a substring?
SCRIPT_FUNCTION(contains) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM(String, match);
SCRIPT_PARAM_C(String, input);
SCRIPT_PARAM_C(String, match);
SCRIPT_RETURN(input.find(match) != String::npos);
}
SCRIPT_RULE_1(format, String, format) {
SCRIPT_RULE_1_C(format, String, format) {
String fmt = _("%") + replace_all(format, _("%"), _(""));
// determine type expected by format string
if (format.find_first_of(_("DdIiOoXx")) != String::npos) {
SCRIPT_PARAM(int, input);
SCRIPT_PARAM_C(int, input);
SCRIPT_RETURN(String::Format(fmt, input));
} else if (format.find_first_of(_("EeFfGg")) != String::npos) {
SCRIPT_PARAM(double, input);
SCRIPT_PARAM_C(double, input);
SCRIPT_RETURN(String::Format(fmt, input));
} else if (format.find_first_of(_("Ss")) != String::npos) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
SCRIPT_RETURN(format_string(fmt, input));
} else {
throw ScriptError(_ERROR_1_("unsupported format", format));
@@ -101,7 +104,7 @@ SCRIPT_RULE_1(format, String, format) {
}
SCRIPT_FUNCTION(curly_quotes) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
bool open = true, in_tag = false;
FOR_EACH(c, input) {
if (c == _('\'') || c == LEFT_SINGLE_QUOTE || c == RIGHT_SINGLE_QUOTE) {
@@ -122,7 +125,7 @@ SCRIPT_FUNCTION(curly_quotes) {
// regex escape a string
SCRIPT_FUNCTION(regex_escape) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
SCRIPT_RETURN(regex_escape(input));
}
@@ -152,18 +155,18 @@ String replace_tag_contents(String input, const String& tag, const ScriptValueP&
}
// Replace the contents of a specific tag
SCRIPT_RULE_2(tag_contents, String, tag, ScriptValueP, contents) {
SCRIPT_PARAM(String, input);
SCRIPT_RULE_2_C(tag_contents, String, tag, ScriptValueP, contents) {
SCRIPT_PARAM_C(String, input);
SCRIPT_RETURN(replace_tag_contents(input, tag, contents, ctx));
}
SCRIPT_RULE_1(tag_remove, String, tag) {
SCRIPT_PARAM(String, input);
SCRIPT_RULE_1_C(tag_remove, String, tag) {
SCRIPT_PARAM_C(String, input);
SCRIPT_RETURN(remove_tag(input, tag));
}
SCRIPT_FUNCTION(remove_tags) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
SCRIPT_RETURN(untag_no_escape(input));
}
@@ -278,30 +281,30 @@ SCRIPT_FUNCTION_DEPENDENCIES(position_of) {
int script_length_of(Context& ctx, const ScriptValueP& collection) {
if (ScriptObject<Set*>* setobj = dynamic_cast<ScriptObject<Set*>*>(collection.get())) {
Set* set = setobj->getValue();
SCRIPT_OPTIONAL_PARAM_(ScriptValueP, filter);
SCRIPT_OPTIONAL_PARAM_C_(ScriptValueP, filter);
return set->numberOfCards(filter);
} else {
return collection->itemCount();
}
}
SCRIPT_FUNCTION(length) {
SCRIPT_PARAM(ScriptValueP, input);
SCRIPT_PARAM_C(ScriptValueP, input);
SCRIPT_RETURN(script_length_of(ctx, input));
}
SCRIPT_FUNCTION(number_of_items) {
SCRIPT_PARAM(ScriptValueP, in);
SCRIPT_PARAM_C(ScriptValueP, in);
SCRIPT_RETURN(script_length_of(ctx, in));
}
// filtering items from a list
SCRIPT_FUNCTION(filter_list) {
SCRIPT_PARAM(ScriptValueP, input);
SCRIPT_PARAM(ScriptValueP, filter);
SCRIPT_PARAM_C(ScriptValueP, input);
SCRIPT_PARAM_C(ScriptValueP, filter);
// filter a collection
intrusive_ptr<ScriptCustomCollection> ret(new ScriptCustomCollection());
ScriptValueP it = input->makeIterator(input);
while (ScriptValueP v = it->next()) {
ctx.setVariable(_("input"), v);
ctx.setVariable(SCRIPT_VAR_input, v);
if (*filter->eval(ctx)) {
ret->value.push_back(v);
}
@@ -311,7 +314,7 @@ SCRIPT_FUNCTION(filter_list) {
}
SCRIPT_FUNCTION(sort_list) {
SCRIPT_PARAM(ScriptValueP, input);
SCRIPT_PARAM_C(ScriptValueP, input);
SCRIPT_PARAM_N(ScriptValueP, _("order by"), order_by);
return sort_script(ctx, input, *order_by);
}
@@ -320,8 +323,8 @@ SCRIPT_FUNCTION(sort_list) {
SCRIPT_RULE_2_N_DEP(expand_keywords, ScriptValueP, _("default expand"), default_expand,
ScriptValueP, _("combine"), combine) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM(Set*, set);
SCRIPT_PARAM_C(String, input);
SCRIPT_PARAM_C(Set*, set);
KeywordDatabase& db = set->keyword_db;
if (db.empty()) {
db.prepare_parameters(set->game->keyword_parameter_types, set->game->keywords);
@@ -329,20 +332,20 @@ SCRIPT_RULE_2_N_DEP(expand_keywords, ScriptValueP, _("default expand"), default_
db.add(set->game->keywords);
db.add(set->keywords);
}
SCRIPT_OPTIONAL_PARAM_(CardP, card);
SCRIPT_OPTIONAL_PARAM_C_(CardP, card);
WITH_DYNAMIC_ARG(keyword_usage_statistics, card ? &card->keyword_usage : nullptr);
SCRIPT_RETURN(db.expand(input, default_expand, combine, ctx));
}
SCRIPT_RULE_2_DEPENDENCIES(expand_keywords) {
default_expand->dependencies(ctx, dep);
combine ->dependencies(ctx, dep);
SCRIPT_PARAM(Set*, set);
SCRIPT_PARAM_C(Set*, set);
set->game->dependent_scripts_keywords.add(dep); // this depends on the set's keywords
SCRIPT_RETURN(_(""));
}
SCRIPT_FUNCTION(keyword_usage) {
SCRIPT_PARAM(CardP, card);
SCRIPT_PARAM_C(CardP, card);
SCRIPT_OPTIONAL_PARAM_(bool, unique);
// make a list "kw1, kw2, kw3" of keywords used on card
String ret;
@@ -372,7 +375,7 @@ class ScriptReplaceRule : public ScriptValue {
virtual ScriptType type() const { return SCRIPT_FUNCTION; }
virtual String typeName() const { return _("replace_rule"); }
virtual ScriptValueP eval(Context& ctx) const {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
if (context.IsValid() || replacement_function || recursive) {
SCRIPT_RETURN(apply(ctx, input));
} else {
@@ -431,12 +434,12 @@ class ScriptReplaceRule : public ScriptValue {
ScriptValueP replace_rule(Context& ctx) {
intrusive_ptr<ScriptReplaceRule> ret(new ScriptReplaceRule);
// match
SCRIPT_PARAM(String, match);
SCRIPT_PARAM_C(String, match);
if (!ret->regex.Compile(match, wxRE_ADVANCED)) {
throw ScriptError(_("Error while compiling regular expression: '")+match+_("'"));
}
// replace
SCRIPT_PARAM(ScriptValueP, replace);
SCRIPT_PARAM_C(ScriptValueP, replace);
if (replace->type() == SCRIPT_FUNCTION) {
ret->replacement_function = replace;
} else {
@@ -467,7 +470,7 @@ class ScriptFilterRule : public ScriptValue {
virtual ScriptType type() const { return SCRIPT_FUNCTION; }
virtual String typeName() const { return _("filter_rule"); }
virtual ScriptValueP eval(Context& ctx) const {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
String ret;
while (regex.Matches(input)) {
// match, append to result
@@ -493,7 +496,7 @@ class ScriptFilterRule : public ScriptValue {
ScriptValueP filter_rule(Context& ctx) {
intrusive_ptr<ScriptFilterRule> ret(new ScriptFilterRule);
// match
SCRIPT_PARAM(String, match);
SCRIPT_PARAM_C(String, match);
if (!ret->regex.Compile(match, wxRE_ADVANCED)) {
throw ScriptError(_("Error while compiling regular expression: '")+match+_("'"));
}
@@ -520,7 +523,7 @@ class ScriptMatchRule : public ScriptValue {
virtual ScriptType type() const { return SCRIPT_FUNCTION; }
virtual String typeName() const { return _("match_rule"); }
virtual ScriptValueP eval(Context& ctx) const {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
SCRIPT_RETURN(regex.Matches(input));
}
@@ -531,7 +534,7 @@ class ScriptMatchRule : public ScriptValue {
ScriptValueP match_rule(Context& ctx) {
intrusive_ptr<ScriptMatchRule> ret(new ScriptMatchRule);
// match
SCRIPT_PARAM(String, match);
SCRIPT_PARAM_C(String, match);
if (!ret->regex.Compile(match, wxRE_ADVANCED)) {
throw ScriptError(_("Error while compiling regular expression: '")+match+_("'"));
}
@@ -554,7 +557,7 @@ class ScriptRule_sort_order: public ScriptValue {
virtual ScriptType type() const { return SCRIPT_FUNCTION; }
virtual String typeName() const { return _("sort_rule"); }
virtual ScriptValueP eval(Context& ctx) const {
SCRIPT_PARAM(ScriptValueP, input);
SCRIPT_PARAM_C(ScriptValueP, input);
if (input->type() == SCRIPT_COLLECTION) {
handle_warning(_("Sorting a collection as a string, this is probably not intended, if it is use 'collection+\"\"' to force conversion"), false);
}
@@ -569,7 +572,7 @@ class ScriptRule_sort: public ScriptValue {
virtual ScriptType type() const { return SCRIPT_FUNCTION; }
virtual String typeName() const { return _("sort_rule"); }
virtual ScriptValueP eval(Context& ctx) const {
SCRIPT_PARAM(ScriptValueP, input);
SCRIPT_PARAM_C(ScriptValueP, input);
if (input->type() == SCRIPT_COLLECTION) {
handle_warning(_("Sorting a collection as a string, this is probably not intended, if it is use 'collection+\"\"' to force conversion"), false);
}
@@ -582,13 +585,13 @@ class ScriptRule_sort: public ScriptValue {
};
SCRIPT_FUNCTION(sort_rule) {
SCRIPT_OPTIONAL_PARAM(String, order) {
SCRIPT_OPTIONAL_PARAM_C(String, order) {
return new_intrusive1<ScriptRule_sort_order>(order);
}
return new_intrusive <ScriptRule_sort>();
}
SCRIPT_FUNCTION(sort_text) {
SCRIPT_OPTIONAL_PARAM(String, order) {
SCRIPT_OPTIONAL_PARAM_C(String, order) {
return ScriptRule_sort_order(order).eval(ctx);
}
return ScriptRule_sort().eval(ctx);
+9 -9
View File
@@ -53,7 +53,7 @@ SCRIPT_FUNCTION_WITH_DEP(combined_editor) {
throw ScriptError(String::Format(_("Not enough separators for combine_editor, expected %d"), values.size()-1));
}
// the value
SCRIPT_PARAM(String, value);
SCRIPT_PARAM_C(String, value);
// remove suffix/prefix
SCRIPT_OPTIONAL_PARAM_(String, prefix);
SCRIPT_OPTIONAL_PARAM_(String, suffix);
@@ -147,7 +147,7 @@ SCRIPT_FUNCTION_DEPENDENCIES(combined_editor) {
} else if (i > 0) break;
}
// Find the target field
SCRIPT_PARAM(Set*, set);
SCRIPT_PARAM_C(Set*, set);
GameP game = set->game;
FieldP target_field;
if (dep.type == DEP_CARD_FIELD) target_field = game->card_fields[dep.index];
@@ -183,7 +183,7 @@ SCRIPT_FUNCTION_DEPENDENCIES(combined_editor) {
// convert a full choice name into the name of the top level group it is in
SCRIPT_FUNCTION(primary_choice) {
SCRIPT_PARAM(ValueP,input);
SCRIPT_PARAM_C(ValueP,input);
ChoiceValueP value = dynamic_pointer_cast<ChoiceValue>(input);
if (!value) {
throw ScriptError(_("Argument to 'primary_choice' should be a choice value"));
@@ -222,8 +222,8 @@ bool chosen(const String& choice, const String& input) {
// is the given choice active?
SCRIPT_FUNCTION(chosen) {
SCRIPT_PARAM(String,choice);
SCRIPT_PARAM(String,input);
SCRIPT_PARAM_C(String,choice);
SCRIPT_PARAM_C(String,input);
SCRIPT_RETURN(chosen(choice, input));
}
@@ -311,7 +311,7 @@ void read_choices_param(Context& ctx, vector<String>& choices) {
// add the given choice if it is not already active
SCRIPT_FUNCTION(require_choice) {
SCRIPT_PARAM(String,input);
SCRIPT_PARAM_C(String,input);
SCRIPT_OPTIONAL_PARAM_N_(String,_("last change"),last_change);
vector<String> choices;
read_choices_param(ctx, choices);
@@ -320,7 +320,7 @@ SCRIPT_FUNCTION(require_choice) {
// make sure at most one of the choices is active
SCRIPT_FUNCTION(exclusive_choice) {
SCRIPT_PARAM(String,input);
SCRIPT_PARAM_C(String,input);
SCRIPT_OPTIONAL_PARAM_N_(String,_("last change"),last_change);
vector<String> choices;
read_choices_param(ctx, choices);
@@ -329,7 +329,7 @@ SCRIPT_FUNCTION(exclusive_choice) {
// make sure exactly one of the choices is active
SCRIPT_FUNCTION(require_exclusive_choice) {
SCRIPT_PARAM(String,input);
SCRIPT_PARAM_C(String,input);
SCRIPT_OPTIONAL_PARAM_N_(String,_("last change"),last_change);
vector<String> choices;
read_choices_param(ctx, choices);
@@ -338,7 +338,7 @@ SCRIPT_FUNCTION(require_exclusive_choice) {
// make sure none of the choices are active
SCRIPT_FUNCTION(remove_choice) {
SCRIPT_PARAM(String,input);
SCRIPT_PARAM_C(String,input);
vector<String> choices;
read_choices_param(ctx, choices);
SCRIPT_RETURN(filter_choices(input, choices, 0, 0, _("")));
+7 -7
View File
@@ -133,19 +133,19 @@ String do_english_num(String input, String(*fun)(int)) {
}
SCRIPT_FUNCTION(english_number) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
SCRIPT_RETURN(do_english_num(input, english_number));
}
SCRIPT_FUNCTION(english_number_a) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
SCRIPT_RETURN(do_english_num(input, english_number_a));
}
SCRIPT_FUNCTION(english_number_multiple) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
SCRIPT_RETURN(do_english_num(input, english_number_multiple));
}
SCRIPT_FUNCTION(english_number_ordinal) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
SCRIPT_RETURN(do_english_num(input, english_ordinal));
}
@@ -210,11 +210,11 @@ String do_english(String input, String(*fun)(const String&)) {
}
SCRIPT_FUNCTION(english_singular) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
SCRIPT_RETURN(do_english(input, english_singular));
}
SCRIPT_FUNCTION(english_plural) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
SCRIPT_RETURN(do_english(input, english_plural));
}
@@ -308,7 +308,7 @@ String process_english_hints(const String& str) {
}
SCRIPT_FUNCTION(process_english_hints) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
SCRIPT_RETURN(process_english_hints(input));
}
+7 -7
View File
@@ -252,7 +252,7 @@ String to_html(const String& str_in, const SymbolFontP& symbol_font, double symb
// convert a tagged string to html
SCRIPT_FUNCTION(to_html) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
// symbol font?
SymbolFontP symbol_font;
SCRIPT_OPTIONAL_PARAM_N(String, _("symbol font"), font_name) {
@@ -266,7 +266,7 @@ SCRIPT_FUNCTION(to_html) {
// convert a symbol string to html
SCRIPT_FUNCTION(symbols_to_html) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
SCRIPT_PARAM_N(String, _("symbol font"), font_name);
SCRIPT_OPTIONAL_PARAM_N_(double, _("symbol font size"), symbol_font_size);
SymbolFontP symbol_font = SymbolFont::byName(font_name);
@@ -331,7 +331,7 @@ String to_bbcode(const String& str_in) {
// convert a tagged string to BBCode
SCRIPT_FUNCTION(to_bbcode) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
throw "TODO";
// SCRIPT_RETURN(to_bbcode(input, symbol_font));
}
@@ -340,7 +340,7 @@ SCRIPT_FUNCTION(to_bbcode) {
// convert a tagged string to plain text
SCRIPT_FUNCTION(to_text) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
SCRIPT_RETURN(untag_hide_sep(input));
}
@@ -349,7 +349,7 @@ SCRIPT_FUNCTION(to_text) {
// copy from source package -> destination directory, return new filename (relative)
SCRIPT_FUNCTION(copy_file) {
guard_export_info(_("copy_file"));
SCRIPT_PARAM(String, input); // file to copy
SCRIPT_PARAM_C(String, input); // file to copy
ExportInfo& ei = *export_info();
wxFileName fn(input);
fn.SetPath(ei.directory_absolute);
@@ -364,7 +364,7 @@ SCRIPT_FUNCTION(copy_file) {
// write a file to the destination directory
SCRIPT_FUNCTION(write_text_file) {
guard_export_info(_("write_text_file"));
SCRIPT_PARAM(String, input); // text to write
SCRIPT_PARAM_C(String, input); // text to write
SCRIPT_PARAM(String, file); // file to write to
// filename
wxFileName fn;
@@ -391,7 +391,7 @@ SCRIPT_FUNCTION(write_image_file) {
SCRIPT_RETURN(fn.GetFullName()); // already written an image with this name
}
// get image
SCRIPT_PARAM(ScriptValueP, input);
SCRIPT_PARAM_C(ScriptValueP, input);
SCRIPT_OPTIONAL_PARAM_(int, width);
SCRIPT_OPTIONAL_PARAM_(int, height);
ScriptObject<CardP>* card = dynamic_cast<ScriptObject<CardP>*>(input.get()); // is it a card?
+6 -6
View File
@@ -63,14 +63,14 @@ SCRIPT_FUNCTION(set_mask) {
}
SCRIPT_FUNCTION(set_alpha) {
SCRIPT_PARAM(GeneratedImageP, input);
SCRIPT_PARAM_C(GeneratedImageP, input);
SCRIPT_PARAM(double, alpha);
return new_intrusive2<SetAlphaImage>(input, alpha);
}
SCRIPT_FUNCTION(set_combine) {
SCRIPT_PARAM(String, combine);
SCRIPT_PARAM(GeneratedImageP, input);
SCRIPT_PARAM_C(GeneratedImageP, input);
ImageCombine image_combine;
if (!parse_enum(combine, image_combine)) {
throw ScriptError(_("Not a valid combine mode: '") + combine + _("'"));
@@ -79,13 +79,13 @@ SCRIPT_FUNCTION(set_combine) {
}
SCRIPT_FUNCTION(enlarge) {
SCRIPT_PARAM(GeneratedImageP, input);
SCRIPT_PARAM_C(GeneratedImageP, input);
SCRIPT_PARAM_N(double, _("border size"), border_size);
return new_intrusive2<EnlargeImage>(input, border_size);
}
SCRIPT_FUNCTION(crop) {
SCRIPT_PARAM(GeneratedImageP, input);
SCRIPT_PARAM_C(GeneratedImageP, input);
SCRIPT_PARAM_N(int, _("width"), width);
SCRIPT_PARAM_N(int, _("height"), height);
SCRIPT_PARAM_N(double, _("offset x"), offset_x);
@@ -94,7 +94,7 @@ SCRIPT_FUNCTION(crop) {
}
SCRIPT_FUNCTION(drop_shadow) {
SCRIPT_PARAM(GeneratedImageP, input);
SCRIPT_PARAM_C(GeneratedImageP, input);
SCRIPT_OPTIONAL_PARAM_N_(double, _("offset x"), offset_x);
SCRIPT_OPTIONAL_PARAM_N_(double, _("offset y"), offset_y);
SCRIPT_OPTIONAL_PARAM_N_(double, _("alpha"), alpha);
@@ -156,7 +156,7 @@ SCRIPT_FUNCTION(symbol_variation) {
}
SCRIPT_FUNCTION(built_in_image) {
SCRIPT_PARAM(String, input);
SCRIPT_PARAM_C(String, input);
return new_intrusive1<BuiltInImage>(input);
}
+20
View File
@@ -70,6 +70,14 @@ inline Type from_script(const ScriptValueP& v, const String& str) {
throw ScriptError(_ERROR_2_("in parameter", str, e.what()));
}
}
template <typename Type>
inline Type from_script(const ScriptValueP& v, Variable var) {
try {
return from_script<Type>(v);
} catch (ScriptError& e) {
throw ScriptError(_ERROR_2_("in parameter", variable_to_string(var), e.what()));
}
}
/// Retrieve a parameter to a SCRIPT_FUNCTION with the given name and type
/** Usage:
@@ -85,6 +93,10 @@ inline Type from_script(const ScriptValueP& v, const String& str) {
SCRIPT_PARAM_N(Type, _(#name), name)
#define SCRIPT_PARAM_N(Type, str, name) \
Type name = from_script<Type>(ctx.getVariable(str), str)
/// Faster variant of SCRIPT_PARAM when name is a CommonScriptVariable
/** Doesn't require a runtime lookup of the name */
#define SCRIPT_PARAM_C(Type, name) \
SCRIPT_PARAM_N(Type, SCRIPT_VAR_ ## name, name)
/// Retrieve an optional parameter
/** Usage:
@@ -103,6 +115,8 @@ inline Type from_script(const ScriptValueP& v, const String& str) {
#define SCRIPT_OPTIONAL_PARAM_N(Type, str, name) \
SCRIPT_OPTIONAL_PARAM_N_(Type, str, name) \
if (name##_)
#define SCRIPT_OPTIONAL_PARAM_C(Type, name) \
SCRIPT_OPTIONAL_PARAM_N(Type, SCRIPT_VAR_ ## name, name)
/// Retrieve an optional parameter, can't be used as an if statement
#define SCRIPT_OPTIONAL_PARAM_(Type, name) \
@@ -112,6 +126,8 @@ inline Type from_script(const ScriptValueP& v, const String& str) {
ScriptValueP name##_ = ctx.getVariableOpt(str); \
Type name = name##_ && name##_ != script_nil \
? from_script<Type>(name##_, str) : Type();
#define SCRIPT_OPTIONAL_PARAM_C_(Type, name) \
SCRIPT_OPTIONAL_PARAM_N_(Type, SCRIPT_VAR_ ## name, name)
/// Retrieve an optional parameter with a default value
#define SCRIPT_PARAM_DEFAULT(Type, name, def) \
@@ -126,6 +142,8 @@ inline Type from_script(const ScriptValueP& v, const String& str) {
/// Utility for defining a script rule with a single parameter
#define SCRIPT_RULE_1(funname, type1, name1) \
SCRIPT_RULE_1_N(funname, type1, _(#name1), name1)
#define SCRIPT_RULE_1_C(funname, type1, name1) \
SCRIPT_RULE_1_N(funname, type1, SCRIPT_VAR_ ## name1, name1)
/// Utility for defining a script rule with a single named parameter
#define SCRIPT_RULE_1_N(funname, type1, str1, name1) \
class ScriptRule_##funname: public ScriptValue { \
@@ -150,6 +168,8 @@ inline Type from_script(const ScriptValueP& v, const String& str) {
/// Utility for defining a script rule with two parameters
#define SCRIPT_RULE_2(funname, type1, name1, type2, name2) \
SCRIPT_RULE_2_N(funname, type1, _(#name1), name1, type2, _(#name2), name2)
#define SCRIPT_RULE_2_C(funname, type1, name1, type2, name2) \
SCRIPT_RULE_2_N(funname, type1, SCRIPT_VAR_ ## name1, name1, type2, SCRIPT_VAR_ ## name2, name2)
/// Utility for defining a script rule with two named parameters
#define SCRIPT_RULE_2_N(funname, type1, str1, name1, type2, str2, name2) \
SCRIPT_RULE_2_N_AUX(funname, type1, str1, name1, type2, str2, name2, ;)