예제 #1
0
파일: luac.cpp 프로젝트: aappleby/Lumina
static void PrintConstant(const LuaProto* f, int i)
{
  LuaValue v = f->constants[i];
  if(v.isNil()) {
    printf("nil");
    return;
  }

  if(v.isBool()) {
    printf(v.getBool() ? "true" : "false");
    return;
  }

  if(v.isNumber()) {
    printf(LUA_NUMBER_FMT,v.getNumber());
    return;
  }

  if(v.isString()) {
    PrintString(v.getString());
    return;
  }

  printf("? type=%d",v.type());
}
예제 #2
0
파일: lauxlib.cpp 프로젝트: aappleby/Lumina
void findfield2(LuaThread* L, LuaTable* table1, LuaValue goal, int depth, std::string& result) {

  LuaValue key = table1->findKeyString(goal);

  if(!key.isNone()) {
    result = key.getString()->c_str();
    return;
  }

  if(depth == 0) return;

  int size1 = table1->getTableIndexSize();
  
  for(int i = 0; i < size1; i++) {
    LuaValue key1, val1;
    table1->tableIndexToKeyVal(i, key1, val1);
    if(!key1.isString()) continue;
    if(!val1.isTable()) continue;

    findfield2(L, val1.getTable(), goal, depth-1, result);

    if(result.size()) {
      std::string prefix = key1.getString()->c_str();
      result = prefix + "." + result;
      return;
    }
  }
}
예제 #3
0
void LuaValue::concatFrom(const LuaValue& l, const LuaValue& r) {
    if (l.isTypeOf(LVT_String)) {
        auto str1 = l.getString(), str2 = r.getString();
        int nsize = str1->size() + str2->size();
        vector<char> buf(nsize);
        if (nsize > 0) {
            memcpy(&buf[0], str1->buf(), str1->size());
            memcpy(&buf[0] + str1->size(), str2->buf(), str2->size());
            *this = LuaValue(&buf[0], nsize);
        } else {
            *this = LuaValue("", 0);
        }
    } else {
        *this = meta_concat(l.getTable(), r);
    }
}
예제 #4
0
파일: ldebug.cpp 프로젝트: aappleby/Lumina
/*
** find a "name" for the RK value 'c'
*/
void kname2 (LuaProto *p, int pc, int c, std::string& name) {
  if (ISK(c)) {  /* is 'c' a constant? */
    LuaValue *kvalue = &p->constants[INDEXK(c)];
    if (kvalue->isString()) {  /* literal constant? */
      name = kvalue->getString()->c_str();  /* it is its own name */
      return;
    }
    /* else no reasonable name found */
  }
  else {  /* 'c' is a register */
    const char *what = getobjname2(p, pc, c, name); /* search for 'c' */
    if (what && *what == 'c') {  /* found a constant name? */
      return;  /* 'name' already filled */
    }
    /* else no reasonable name found */
  }
  name = "?";  /* no reasonable name found */
}
예제 #5
0
파일: ldump.cpp 프로젝트: aappleby/Lumina
static void DumpConstants(const LuaProto* f, DumpState* D)
{
  int n = (int)f->constants.size();
  DumpInt(n,D);
  for(int i=0; i < n; i++)
  {
    LuaValue v = f->constants[i];
    DumpChar(v.type(),D);

    if(v.isBool()) {
      DumpChar(v.getBool() ? 1 : 0,D);
    } else if(v.isNumber()) {
      DumpNumber(v.getNumber(),D);
    } else if(v.isString()) {
      DumpString(v.getString(),D);
    }
  }
  n = (int)f->subprotos_.size();
  DumpInt(n,D);
  for (int i=0; i < n; i++) {
    DumpFunction(f->subprotos_[i],D);
  }
}