Commit c2af0830 authored by twanvl's avatar twanvl

Also init dependencies of non rule form expand_keywords

parent fcd75a64
...@@ -232,6 +232,10 @@ ScriptValueP Context::getVariable(Variable var) { ...@@ -232,6 +232,10 @@ ScriptValueP Context::getVariable(Variable var) {
if (variables[var].value) return variables[var].value; if (variables[var].value) return variables[var].value;
throw ScriptError(_("Variable not set: ") + variable_to_string(var)); throw ScriptError(_("Variable not set: ") + variable_to_string(var));
} }
ScriptValueP Context::getVariableInScopeOpt(Variable var) {
if (variables[var].level == level) return variables[var].value;
else return ScriptValueP();
}
int Context::getVariableScope(Variable var) { int Context::getVariableScope(Variable var) {
if (variables[var].value) return level - variables[var].level; if (variables[var].value) return level - variables[var].level;
else return -1; else return -1;
......
...@@ -62,6 +62,8 @@ class Context { ...@@ -62,6 +62,8 @@ class Context {
ScriptValueP getVariable(Variable var); ScriptValueP getVariable(Variable var);
/// Get the value of a variable, returns ScriptValue() if it is not set /// Get the value of a variable, returns ScriptValue() if it is not set
inline ScriptValueP getVariableOpt(Variable var) { return variables[var].value; } inline ScriptValueP getVariableOpt(Variable var) { return variables[var].value; }
/// Get the value of a variable only if it was set in the current scope, returns ScriptValue() if it is not set
ScriptValueP getVariableInScopeOpt(Variable var);
/// In what scope was the variable set? /// In what scope was the variable set?
/** Returns 0 for the current scope and >0 for outer scopes. /** Returns 0 for the current scope and >0 for outer scopes.
* Returns -1 if the varible is not set * Returns -1 if the varible is not set
......
...@@ -314,6 +314,7 @@ SCRIPT_FUNCTION(sort_list) { ...@@ -314,6 +314,7 @@ SCRIPT_FUNCTION(sort_list) {
// ----------------------------------------------------------------------------- : Keywords // ----------------------------------------------------------------------------- : Keywords
SCRIPT_RULE_2_N_DEP(expand_keywords, ScriptValueP, _("default expand"), default_expand, SCRIPT_RULE_2_N_DEP(expand_keywords, ScriptValueP, _("default expand"), default_expand,
ScriptValueP, _("combine"), combine) { ScriptValueP, _("combine"), combine) {
SCRIPT_PARAM_C(String, input); SCRIPT_PARAM_C(String, input);
...@@ -338,7 +339,7 @@ SCRIPT_RULE_2_DEPENDENCIES(expand_keywords) { ...@@ -338,7 +339,7 @@ SCRIPT_RULE_2_DEPENDENCIES(expand_keywords) {
combine ->dependencies(ctx, dep); combine ->dependencies(ctx, dep);
SCRIPT_PARAM_C(Set*, set); SCRIPT_PARAM_C(Set*, set);
set->game->dependent_scripts_keywords.add(dep); // this depends on the set's keywords set->game->dependent_scripts_keywords.add(dep); // this depends on the set's keywords
SCRIPT_RETURN(_("")); return ctx.getVariable(SCRIPT_VAR_input);
} }
SCRIPT_FUNCTION(keyword_usage) { SCRIPT_FUNCTION(keyword_usage) {
......
...@@ -181,13 +181,18 @@ inline Type from_script(const ScriptValueP& v, Variable var) { ...@@ -181,13 +181,18 @@ inline Type from_script(const ScriptValueP& v, Variable var) {
SCRIPT_RULE_2_N(funname, type1, SCRIPT_VAR_ ## name1, name1, type2, SCRIPT_VAR_ ## name2, 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 /// Utility for defining a script rule with two named parameters
#define SCRIPT_RULE_2_N(funname, type1, str1, name1, type2, str2, name2) \ #define SCRIPT_RULE_2_N(funname, type1, str1, name1, type2, str2, name2) \
SCRIPT_RULE_2_N_AUX(funname, type1, str1, name1, type2, str2, name2, ;) SCRIPT_RULE_2_N_AUX(funname, type1, str1, name1, type2, str2, name2, ;, ;)
/// Utility for defining a script rule with two named parameters, with dependencies /// Utility for defining a script rule with two named parameters, with dependencies
#define SCRIPT_RULE_2_N_DEP(funname, type1, str1, name1, type2, str2, name2)\ #define SCRIPT_RULE_2_N_DEP(funname, type1, str1, name1, type2, str2, name2) \
SCRIPT_RULE_2_N_AUX( funname, type1, str1, name1, type2, str2, name2,\ SCRIPT_RULE_2_N_AUX( funname, type1, str1, name1, type2, str2, name2, \
virtual ScriptValueP dependencies(Context&, const Dependency&) const;) virtual ScriptValueP dependencies(Context&, const Dependency&) const;, \
SCRIPT_FUNCTION_DEPENDENCIES(funname) { \
SCRIPT_PARAM_N(type1, str1, name1); \
SCRIPT_PARAM_N(type2, str2, name2); \
return ScriptRule_##funname(name1, name2).dependencies(ctx, dep); \
})
#define SCRIPT_RULE_2_N_AUX(funname, type1, str1, name1, type2, str2, name2, dep) \ #define SCRIPT_RULE_2_N_AUX(funname, type1, str1, name1, type2, str2, name2, dep, more) \
class ScriptRule_##funname: public ScriptValue { \ class ScriptRule_##funname: public ScriptValue { \
public: \ public: \
inline ScriptRule_##funname(const type1& name1, const type2& name2) \ inline ScriptRule_##funname(const type1& name1, const type2& name2) \
...@@ -205,11 +210,12 @@ inline Type from_script(const ScriptValueP& v, Variable var) { ...@@ -205,11 +210,12 @@ inline Type from_script(const ScriptValueP& v, Variable var) {
SCRIPT_PARAM_N(type2, str2, name2); \ SCRIPT_PARAM_N(type2, str2, name2); \
return new_intrusive2<ScriptRule_##funname>(name1, name2); \ return new_intrusive2<ScriptRule_##funname>(name1, name2); \
} \ } \
SCRIPT_FUNCTION(funname) { \ SCRIPT_FUNCTION_AUX(funname, dep) { \
SCRIPT_PARAM_N(type1, str1, name1); \ SCRIPT_PARAM_N(type1, str1, name1); \
SCRIPT_PARAM_N(type2, str2, name2); \ SCRIPT_PARAM_N(type2, str2, name2); \
return ScriptRule_##funname(name1, name2).eval(ctx); \ return ScriptRule_##funname(name1, name2).eval(ctx); \
} \ } \
more \
ScriptValueP ScriptRule_##funname::eval(Context& ctx) const ScriptValueP ScriptRule_##funname::eval(Context& ctx) const
#define SCRIPT_RULE_2_DEPENDENCIES(name) \ #define SCRIPT_RULE_2_DEPENDENCIES(name) \
......
...@@ -278,6 +278,7 @@ void SetScriptManager::updateAll() { ...@@ -278,6 +278,7 @@ void SetScriptManager::updateAll() {
#ifdef LOG_UPDATES #ifdef LOG_UPDATES
wxLogDebug(_("Update all")); wxLogDebug(_("Update all"));
#endif #endif
wxBusyCursor busy;
// update set data // update set data
Context& ctx = getContext(set.stylesheet); Context& ctx = getContext(set.stylesheet);
FOR_EACH(v, set.data) { FOR_EACH(v, set.data) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment