Пример #1
0
/* Free the space allocated for the script */
void script_free(struct script_cmd* script)
{
	while (script) {
		struct script_cmd* next;
		switch (script_cmd_type_get(script->type)) {
		case SCRIPT_CMD_TYPE_1C:
			script_free(script->data.op1c.arg0);
			break;
		case SCRIPT_CMD_TYPE_1E:
			script_exp_free(script->data.op1e.arg0);
			break;
		case SCRIPT_CMD_TYPE_1ED:
			script_exp_free(script->data.op1ed.arg0);
			break;
		case SCRIPT_CMD_TYPE_2EC:
			script_exp_free(script->data.op2ec.arg0);
			script_free(script->data.op2ec.arg1);
			break;
		case SCRIPT_CMD_TYPE_2ECD:
			script_exp_free(script->data.op2ecd.arg0);
			script_free(script->data.op2ecd.arg1);
			break;
		}
		next = script->next;
		free(script);
		script = next;
	}
}
Пример #2
0
static struct script *script_parse(struct buff *buf) {
  struct script *script;
  bool error = 0;

  script = script_alloc();

  while (1) {
    struct script_inst inst;
    bool s;

    s = script_parse_one_op(buf, &inst, &error);
    if (s == 0) {
      break;
    }
    script->inst[script->len] = inst;
    script->len++;
    script_check_resize(script);
  }
  if (error == 0) {
    return script;
  }

  script_free(script);
  return NULL;
}
Пример #3
0
int main(int argc, char **argv)
#endif
{
    // NOTE: somehow when defining script as a public member of SampleApp, Listener won't return the correct reference to lua refs. No problem if the ref is called within SampleApp
    // I think this has to do with the map, with char* as key. the address might have changed
    SCRIPT = script_new();
    script_bind(SCRIPT);
    script_run(SCRIPT, "autoexec.lua");
    std::cout << script_stack_size(SCRIPT) << std::endl;
    printf("address of script: %d\n", SCRIPT);
    //std::cout << script_stack_size(SCRIPT) << std::endl;
    //lua_pushinteger(SCRIPT->L, 1);
    //script_pcallback(SCRIPT, "game.on_mouseclick", 1, 0);
    //script_stack_pop(SCRIPT, 0);
    //std::cout << script_stack_size(SCRIPT) << std::endl;

    srand(time(NULL));
    try {
        APP = new SampleApp();
        APP->go();
    } catch (Ogre::Exception& e) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
        MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
        std::cerr << "Exception:\n";
        std::cerr << e.getFullDescription().c_str() << "\n";
#endif
        return 1;
    }

    delete APP;
    script_free(SCRIPT);

    return 0;
}
Пример #4
0
void script_cache_free(script_cache *p) {
	size_t i;

	if (!p) return;

	for (i = 0; i < p->used; i++) {
		script_free(p->ptr[i]);
	}

	free(p->ptr);

	free(p);
}
Пример #5
0
static int script_match_type(struct buff *buf, enum script_txout_type *type,
                             uint8 **data_addr, size_t *data_len) {
  struct script *script;

  ASSERT(type);
  ASSERT(data_addr);
  ASSERT(data_len);

  *data_addr = NULL;

  script = script_parse(buf);
  if (script == NULL) {
    NOT_TESTED();
    return 1;
  }

  *type = script_classify(script);

  switch (*type) {
    case TX_PUBKEY:
      *data_len = script->inst[0].len;
      *data_addr = safe_malloc(*data_len);
      memcpy(*data_addr, script->inst[0].data, *data_len);
      ASSERT(*data_addr);
      break;
    case TX_PUBKEYHASH:
      *data_len = script->inst[2].len;
      *data_addr = safe_malloc(*data_len);
      ASSERT(*data_len == sizeof(uint160));
      memcpy(*data_addr, script->inst[2].data, *data_len);
      break;
    default:
      *data_addr = NULL;
      *data_len = 0;
      break;
  }

  script_free(script);
  return 0;
}
Пример #6
0
void scripts_load() {
	GSList* dir;
	GList* s;
	unsigned i;
	char path[PATH_MAX];

	if (!scriptdata) {
		g_datalist_init(&scriptdata);
	}

	/*
	   g_datalist_get_data(&scriptdata, "foo");
	   g_datalist_set_data_full(&scriptdata,"foo",value,g_free);
	*/

	for (dir = scriptdirs; dir; dir = g_slist_next(dir)) {
		GList* s = dir_to_list(dir->data, script_filter);
		scripts = merge_sorted_string_lists(scripts, s);
	}

	for (s = scripts; s; s = g_list_next(s)) {
		unsigned version;
		config_section_iterator* sit;
		Script* script;
		const char* filename = s->data;
		char* errtitle = _("Script error");

		// already known?
		if (g_datalist_get_data(&scriptdata, filename)) {
			continue;
		}

		script = script_new();

		snprintf(path, sizeof(path), "/scripts/%s/General", filename);
		config_push_prefix(path);

		version = config_get_int("xqf version");
		script->summary = config_get_string("summary");
		script->author = config_get_string("author");
		script->license = config_get_string("license");

		config_pop_prefix();

		if (version > MAX_SCRIPT_VERSION) {
			dialog_ok(errtitle, _("Script %s has version %d, xqf only supports version %d."),
					filename, version, MAX_SCRIPT_VERSION);
			script_free(script);
			continue;
		}

		if (!script->summary) {
			dialog_ok(errtitle, _("Script %s missing summary."), filename);
			script_free(script);
			continue;
		}
		if (!script->author) {
			dialog_ok(errtitle, _("Script %s missing author."), filename);
			script_free(script);
			continue;
		}
		if (!script->license) {
			dialog_ok(errtitle, _("Script %s missing license."), filename);
			script_free(script);
			continue;
		}

		script->name = g_strdup(filename);

		snprintf(path, sizeof(path), "/scripts/%s/Action", filename);
		config_push_prefix(path);

		for (i = 0; i < NUM_ACTIONS; ++i) {
			gboolean on = config_get_bool(action_key[i]);
			if (on) {
				action[i] = g_slist_prepend(action[i], script);
			}
		}

		config_pop_prefix();

		// treat script property 'enabled' as option as it has a widget
		// so it's easier to handle later
		{
			ScriptOption* opt;
			snprintf(path, sizeof(path), "/" CONFIG_FILE "/scripts/%s/enabled=false", filename);

			opt = scriptoption_new("bool");
			opt->enable = config_get_bool(path);
			// Translator: whether this plugin script is enabled
			opt->name = _("Enabled");
			opt->section = g_strdup("enabled");
			script->options = g_slist_prepend(script->options, opt);
		}

		snprintf(path, sizeof(path), "/scripts/%s", filename);
		sit = config_init_section_iterator(path);

		while (sit) {
			char* sname = NULL;

			sit = config_section_iterator_next(sit, &sname);

			if (strlen(sname) > 7 && !strncmp(sname, "option ", 7)) {
				char* typestr;
				char* name;
				ScriptOption* opt;
				char settings_path[PATH_MAX];

				snprintf(settings_path, sizeof(settings_path), "/" CONFIG_FILE "/scripts/%s/%s", filename, sname);

				snprintf(path, sizeof(path), "/scripts/%s/%s", filename, sname);
				config_push_prefix(path);

				typestr = config_get_string("type");
				name = config_get_string("name");

				opt = scriptoption_new(typestr);

				g_free(typestr);

				if (!opt || !name) {
					xqf_warning("script %s: invalid option %s", filename, sname+7);
					goto next;
				}

				opt->name = name;
				opt->section = sname;

				switch(opt->type) {
					case SCRIPT_OPTION_TYPE_LIST:
						{
							config_key_iterator* it;

							it = config_init_iterator(path);

							if (!opt->list) {
								opt->list = g_ptr_array_new();
							}

							while (it) {
								char* key = NULL;
								char* val = NULL;

								it = config_iterator_next(it, &key, &val);

								if (!strncmp(key, "value",5)) {
									g_ptr_array_add(opt->list, val);
								}
								else {
									g_free(val);
								}

								g_free(key);
							}
						}
					// fall through
					case SCRIPT_OPTION_TYPE_STRING:
					case SCRIPT_OPTION_TYPE_INT:
						{
							char* defval = NULL;
							char* curval = NULL;

							defval = config_get_string("default");
							curval = config_get_string(settings_path);

							if (curval) {
								opt->defval = g_strdup(curval);
							}
							else if (defval) {
								opt->defval = g_strdup(defval);
							}

							g_free(defval);
							g_free(curval);
						}
						break;
					case SCRIPT_OPTION_TYPE_BOOL:
						{
							gboolean defval;
							gboolean curval;
							int is_deflt = 0;

							defval = config_get_bool("default=false");
							curval = config_get_bool_with_default(settings_path, &is_deflt);

							if (is_deflt) {
								opt->enable = defval;
							}
							else {
								opt->enable = curval;
							}
						}
						break;

					case SCRIPT_OPTION_TYPE_INVALID:
						xqf_error("unreachable code");
						break;
				}

				script->options = g_slist_prepend(script->options, opt);

next:
				config_pop_prefix();
			}
		}

		script->options = g_slist_reverse(script->options);

		g_datalist_set_data_full(&scriptdata, filename, script, (GDestroyNotify)script_free);

		snprintf(path, sizeof(path), "/scripts/%s", filename);
		config_drop_file(path);
	}
}