mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
Optimize default arguments (@ operator) into script rules.
The plan is to deprecate rule form completely, so instead of replace_rule(match:..) write replace_text@(match: ...) git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@987 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -611,9 +611,18 @@ ScriptValueP match_rule(Context& ctx) {
|
||||
SCRIPT_FUNCTION(match_rule) {
|
||||
return match_rule(ctx);
|
||||
}
|
||||
SCRIPT_FUNCTION(match) {
|
||||
SCRIPT_FUNCTION_WITH_SIMPLIFY(match) {
|
||||
return match_rule(ctx)->eval(ctx);
|
||||
}
|
||||
SCRIPT_FUNCTION_SIMPLIFY_CLOSURE(match) {
|
||||
ScriptValueP match = closure.getBinding(SCRIPT_VAR_match);
|
||||
if (match) {
|
||||
intrusive_ptr<ScriptMatchRule> ret(new ScriptMatchRule);
|
||||
from_script(match, ret->regex);
|
||||
return ret;
|
||||
}
|
||||
return ScriptValueP();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Rules : sort text
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ void init_script_editor_functions(Context& ctx);
|
||||
void init_script_export_functions(Context& ctx);
|
||||
void init_script_english_functions(Context& ctx);
|
||||
|
||||
/// Initialize all build in functions for a context
|
||||
/// Initialize all built in functions for a context
|
||||
inline void init_script_functions(Context& ctx) {
|
||||
init_script_basic_functions(ctx);
|
||||
init_script_image_functions(ctx);
|
||||
|
||||
@@ -42,20 +42,27 @@
|
||||
SCRIPT_FUNCTION_AUX(name, virtual ScriptValueP dependencies(Context&, const Dependency&) const;)
|
||||
|
||||
#define SCRIPT_FUNCTION_DEPENDENCIES(name) \
|
||||
ScriptValueP ScriptBuildin_##name::dependencies(Context& ctx, const Dependency& dep) const
|
||||
ScriptValueP ScriptBuiltIn_##name::dependencies(Context& ctx, const Dependency& dep) const
|
||||
|
||||
/// Macro to declare a new script function with custom closure simplification
|
||||
#define SCRIPT_FUNCTION_WITH_SIMPLIFY(name) \
|
||||
SCRIPT_FUNCTION_AUX(name, virtual ScriptValueP simplifyClosure(ScriptClosure&) const;)
|
||||
|
||||
#define SCRIPT_FUNCTION_SIMPLIFY_CLOSURE(name) \
|
||||
ScriptValueP ScriptBuiltIn_##name::simplifyClosure(ScriptClosure& closure) const
|
||||
|
||||
// helper for SCRIPT_FUNCTION and SCRIPT_FUNCTION_DEP
|
||||
#define SCRIPT_FUNCTION_AUX(name,dep) \
|
||||
class ScriptBuildin_##name : public ScriptValue { \
|
||||
class ScriptBuiltIn_##name : public ScriptValue { \
|
||||
dep \
|
||||
virtual ScriptType type() const \
|
||||
{ return SCRIPT_FUNCTION; } \
|
||||
virtual String typeName() const \
|
||||
{ return _("build in function '") _(#name) _("'"); } \
|
||||
{ return _("built-in function '") _(#name) _("'"); } \
|
||||
virtual ScriptValueP eval(Context&) const; \
|
||||
}; \
|
||||
ScriptValueP script_##name(new ScriptBuildin_##name); \
|
||||
ScriptValueP ScriptBuildin_##name::eval(Context& ctx) const
|
||||
ScriptValueP script_##name(new ScriptBuiltIn_##name); \
|
||||
ScriptValueP ScriptBuiltIn_##name::eval(Context& ctx) const
|
||||
|
||||
/// Return a value from a SCRIPT_FUNCTION
|
||||
#define SCRIPT_RETURN(value) return to_script(value)
|
||||
|
||||
Reference in New Issue
Block a user