Example #1
0
Variables ScriptManager::callFunction(const Common::UString &name, const Variables &params) {
	assert(!name.empty());
	assert(_luaState && _regNestingLevel == 0);

	std::vector<Common::UString> parts;
	Common::UString::split(name, '.', parts);
	if (parts.empty()) {
		error("Lua call \"%s\" failed: bad name", name.c_str());
		return Variables();
	}

	const Common::UString funcName = parts.back();
	parts.pop_back();

	if (parts.empty()) {
		return getGlobalFunction(funcName).call(params);
	}

	TableRef table = getGlobalTable(parts[0]);
	for (uint32 i = 1; i < parts.size(); ++i) {
		table = table.getTableAt(parts[i]);
	}
	return table.getFunctionAt(funcName).call(params);
}