예제 #1
0
    LUABIND_API void push_instance_metatable(lua_State* L)
    {
        lua_newtable(L);

        // just indicate that this really is a class and not just
        // any user data
        lua_pushboolean(L, 1);
        lua_setfield(L, -2, "__luabind_class");

        // This is used as a tag to determine if a userdata is a luabind
        // instance. We use a numeric key and a cclosure for fast comparision.
        lua_pushnumber(L, 1);
        lua_pushcclosure(L, get_instance_value, 0);
        lua_rawset(L, -3);

        lua_pushcclosure(L, destroy_instance, 0);
        lua_setfield(L, -2, "__gc");

        lua_pushcclosure(L, get_instance_value, 0);
        lua_setfield(L, -2, "__index");

        lua_pushcclosure(L, set_instance_value, 0);
        lua_setfield(L, -2, "__newindex");

        // Creates operator
        for (int op = 0; op < number_of_operators; ++op)
        {
            lua_pushstring(L, get_operator_name(op));
            lua_pushvalue(L, -1);
            lua_pushboolean(L, op == op_unm || op == op_len);
            lua_pushcclosure(L, &dispatch_operator, 2);
            lua_settable(L, -3);
        }
    }
예제 #2
0
void cpp_gen::visit(const mfast::decimal_field_instruction* inst, void*)
{
  std::string name( cpp_name( inst ) );
  if (inst->mantissa_instruction() ) {
    // it has a separate mantissa instruction
    std::string mantisa_name(name);
    mantisa_name += "_mantissa";
    std::string context = gen_op_context(mantisa_name.c_str(), inst->mantissa_instruction()->op_context());

    out_ << "static mantissa_field_instruction\n"
         << prefix_string() << mantisa_name << "_instruction(\n"
         << "  " << get_operator_name(inst->mantissa_instruction()) << ",\n"
         << "  "<< context << ",  // mantissa opContext\n"
         << "  int_value_storage<int64_t>("
         << get_initial_value<int64_t>(inst->mantissa_instruction()->initial_value(), "LL")
         << "));// mantissa inital value\n\n";
  }

  gen_field(inst, gen_op_context(inst->name(), inst->op_context()), "decimal");

  if ( inst->mantissa_instruction() ) {
    out_ << "  &" << prefix_string() << name << "_mantissa_instruction,\n";
  }

  const mfast::value_storage& init_value = inst->initial_value();

  out_ << "  decimal_value_storage(";
  if (!init_value.is_empty())
    out_ <<  init_value.of_decimal.mantissa_ << "LL, " << static_cast<int> (init_value.of_decimal.exponent_);
  out_ << ")); // initial_value\n\n";

}
예제 #3
0
void cpp_gen::visit(const mfast::sequence_field_instruction* inst, void*)
{
  std::string name( cpp_name( inst ) );
  std::size_t index = inst->field_index();

  add_to_instruction_list(name);
  prefixes_.push_back(name);

  if (inst->length_instruction()) {
    std::string context = gen_op_context(inst->length_instruction()->name(),
                                         inst->length_instruction()->op_context());

    // length
    out_ << "static uint32_field_instruction\n"
         << prefix_string() << name << "_length_instruction(\n"
         << "  0,"
         << "  " << get_operator_name(inst->length_instruction()) << ",\n"
         << "  " << get_presence(inst->length_instruction()) << ",\n"
         << "  " << inst->length_instruction()->id() << ", // id\n"
         << "  \""<< inst->length_instruction()->name() << "\", // name\n"
         << "  \""<< inst->length_instruction()->ns() << "\", // ns\n"
         << "  "<< context << ",  // opContext\n"
         << "  int_value_storage<uint32_t>(";
    if (!inst->length_instruction()->initial_value().is_empty())
      out_ << inst->length_instruction()->initial_value().get<uint32_t>() << "U";
    out_ <<  ")); // initial_value\n\n";
  }


  if ( !contains_only_templateRef(inst) ) {
    subinstructions_list_.resize(subinstructions_list_.size()+1);
    traverse(inst, "_element");
  }

  std::string lengthInstruction;

  if (inst->length_instruction()) {
    std::stringstream strm;
    strm << "&" << prefix_string()  << name <<  "_length_instruction";
    lengthInstruction = strm.str();
  }

  std::string subinstruction_arg = get_subinstructions(inst);

  out_ << "const static mfast::sequence_field_instruction\n"
       << prefix_string() << name << "_instruction(\n"
       << "  "<<  index << ",\n"
       << "  " << get_presence(inst) << ",\n"
       << "  " << inst->id() << ", // id\n"
       << "  \"" << inst->name() << "\", // name\n"
       << "  \"" << inst->ns() << "\", // ns\n"
       << "  \"" << inst->dictionary() << "\", // dictionary\n"
       << subinstruction_arg
       << "  "<< lengthInstruction << ", // length\n"
       << "  \"" << inst->typeref_name() << "\", // typeRef name \n"
       << "  \"" << inst->typeref_ns() << "\"); // typeRef ns \n\n";
}
예제 #4
0
void cpp_gen::gen_field(const mfast::field_instruction* inst,
                        const std::string&              context,
                        const char*                     cpp_type)
{
  std::string name( cpp_name( inst ) );
  std::size_t index = inst->field_index();
  // std::string context = gen_op_context(inst->name(), inst->op_context());

  out_ << "const static " << cpp_type << "_field_instruction\n"
       << prefix_string() << name << "_instruction(\n"
       << "  " << index << ",\n"
       << "  " << get_operator_name(inst) << ",\n"
       << "  " << get_presence(inst) << ",\n"
       << "  " << inst->id() << ", // id\n"
       << "  \""<< inst->name() << "\", // name\n"
       << "  \""<< inst->ns() << "\", // ns\n"
       << "  "<< context << ",  // opContext\n";

  add_to_instruction_list(name);
}