lullaby/tools/common/json_utils.cc
/// Callback used by jsonnet for opening files.
Callback used by jsonnet for opening files.
Callback used by jsonnet for opening files .
char* JsonnetImportCallback(void* ctx, const char* base, const char* rel,
                            char** found_here, int* success) {
  std::string data;
  *success = LoadFile(rel, false, &data) ? 1 : 0;
  if (*success == 0) {
    char* res = jsonnet_realloc((struct JsonnetVm*)ctx, nullptr, 1);
    res[0] = 0;
    return res;
  }
  if (found_here) {
    *found_here = jsonnet_realloc((struct JsonnetVm*)ctx, nullptr, 2);
    (*found_here)[0] = '.';
    (*found_here)[1] = 0;
  }
  const size_t len = data.size();
  char* mem = jsonnet_realloc((struct JsonnetVm*)ctx, nullptr, len + 1);
  memcpy(mem, data.c_str(), len);
  mem[len] = 0;
  return mem;
}
char * JsonnetImportCallback ( void * ctx , const char * base , const char * rel , char * * found_here , int * success ) { std :: string data ; * success = LoadFile ( rel , false , & data ) ? 1 : 0 ; if ( * success == 0 ) { char * res = jsonnet_realloc ( ( struct JsonnetVm * ) ctx , nullptr , 1 ) ; res [ 0 ] = 0 ; return res ; } if ( found_here ) { * found_here = jsonnet_realloc ( ( struct JsonnetVm * ) ctx , nullptr , 2 ) ; ( * found_here ) [ 0 ] = ' ' ; ( * found_here ) [ 1 ] = 0 ; } const size_t len = data . size ( ) ; char * mem = jsonnet_realloc ( ( struct JsonnetVm * ) ctx , nullptr , len + 1 ) ; memcpy ( mem , data . c_str ( ) , len ) ; mem [ len ] = 0 ; return mem ; }
Callback used by jsonnet for opening files.
Callback used by jsonnet for opening files .
// Found here may be returning a relative path. // Set found_here to "." (root folder) so further imports will be done // correctly.