Beispiel #1
0
void ASPacketGenerator::code_generate(ofstream& o_file, const MemItemVec& mem_vec)
{
    o_file << "package notifications" << endl
           << "{" << endl
           << "\timport flash.utils.ByteArray;" << endl
           << "\timport flash.utils.Endian;" << endl
           << "\tpublic class " << class_name_ << endl
           << "\t{" << endl;
    if (!msg_id_.empty())
    {
        o_file << "\t\tstatic public const MSGID : uint = " << msg_id_
               << GET_VARDEFMAP()->fetch_value(msg_id_) << ";" << endl << endl;
    }

    generate_members(o_file, mem_vec);
    func_constructor(o_file, mem_vec);

    if (generator_ != NULL)
    {
        generator_->code_generate(o_file, mem_vec);
    }

    o_file << "\t}" << endl
           << "}" << endl;
}
	chaiscript::Boxed_Value ScriptManager::callFunction(chaiscript::ChaiScript& script, const String& name, std::vector<chaiscript::Boxed_Value>& args)
	{
		String argsName = "args";
		if(name.equals(argsName))
		{
			argsName = "params";
		}
		String callHead = (String)"fun(" + argsName + "){ return ";
		String callString =  name + "(";
		for(unsigned int i = 0; i < args.size(); i++)
		{
			callString += argsName + "[" + i + "]";
			if(i != (args.size() - 1))
			{
				callString += ",";
			}
		}
		callString += ");}";

		std::function<chaiscript::Boxed_Value(std::vector<chaiscript::Boxed_Value>&)> func_constructor;

		//first try calling it with "this" keyword.
		try
		{
			func_constructor = script.eval<std::function<chaiscript::Boxed_Value(std::vector<chaiscript::Boxed_Value>&)>>(callHead + "this." + callString);
		}
		catch(const chaiscript::exception::eval_error&)
		{
			//No function with that name exists in that class.
		}

		//try again without "this" keyword"
		try
		{
			func_constructor = script.eval<std::function<chaiscript::Boxed_Value(std::vector<chaiscript::Boxed_Value>&)>>(callHead + callString);
		}
		catch(const chaiscript::exception::eval_error&)
		{
			throw chaiscript::exception::eval_error((String)"no function exists with the name " + name);
		}

		return func_constructor(args);
	}