Data Structures | Macros | Functions
converter.c File Reference
#include <assert.h>
#include <stddef.h>
#include <stdlib.h>
#include "nvim/api/private/converter.h"
#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/eval/typval.h"
#include "nvim/eval/userfunc.h"
#include "nvim/lua/converter.h"
#include "nvim/lua/executor.h"
#include "nvim/eval/typval_encode.c.h"

Data Structures

struct  EncodedData
 Helper structure for vim_to_object. More...
 

Macros

#define TYPVAL_ENCODE_ALLOW_SPECIALS   false
 
#define TYPVAL_ENCODE_CONV_NIL(tv)   kvi_push(edata->stack, NIL)
 
#define TYPVAL_ENCODE_CONV_BOOL(tv, num)   kvi_push(edata->stack, BOOLEAN_OBJ((Boolean)(num)))
 
#define TYPVAL_ENCODE_CONV_NUMBER(tv, num)   kvi_push(edata->stack, INTEGER_OBJ((Integer)(num)))
 
#define TYPVAL_ENCODE_CONV_UNSIGNED_NUMBER   TYPVAL_ENCODE_CONV_NUMBER
 
#define TYPVAL_ENCODE_CONV_FLOAT(tv, flt)   kvi_push(edata->stack, FLOAT_OBJ((Float)(flt)))
 
#define TYPVAL_ENCODE_CONV_STRING(tv, str, len)
 
#define TYPVAL_ENCODE_CONV_STR_STRING   TYPVAL_ENCODE_CONV_STRING
 
#define TYPVAL_ENCODE_CONV_EXT_STRING(tv, str, len, type)   TYPVAL_ENCODE_CONV_NIL(tv)
 
#define TYPVAL_ENCODE_CONV_BLOB(tv, blob, len)
 
#define TYPVAL_ENCODE_CONV_FUNC_START(tv, fun)
 
#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_ARGS(tv, len)
 
#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF(tv, len)
 
#define TYPVAL_ENCODE_CONV_FUNC_END(tv)
 
#define TYPVAL_ENCODE_CONV_EMPTY_LIST(tv)   kvi_push(edata->stack, ARRAY_OBJ(((Array) { .capacity = 0, .size = 0 })))
 
#define TYPVAL_ENCODE_CONV_EMPTY_DICT(tv, dict)
 
#define TYPVAL_ENCODE_CONV_LIST_START(tv, len)   typval_encode_list_start(edata, (size_t)(len))
 
#define TYPVAL_ENCODE_CONV_REAL_LIST_AFTER_START(tv, mpsv)
 
#define TYPVAL_ENCODE_CONV_LIST_BETWEEN_ITEMS(tv)   typval_encode_between_list_items(edata)
 
#define TYPVAL_ENCODE_CONV_LIST_END(tv)   typval_encode_list_end(edata)
 
#define TYPVAL_ENCODE_CONV_DICT_START(tv, dict, len)   typval_encode_dict_start(edata, (size_t)(len))
 
#define TYPVAL_ENCODE_CONV_REAL_DICT_AFTER_START(tv, dict, mpsv)
 
#define TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK(label, kv_pair)
 
#define TYPVAL_ENCODE_CONV_DICT_AFTER_KEY(tv, dict)   typval_encode_after_key(edata)
 
#define TYPVAL_ENCODE_CONV_DICT_BETWEEN_ITEMS(tv, dict)   typval_encode_between_dict_items(edata)
 
#define TYPVAL_ENCODE_CONV_DICT_END(tv, dict)   typval_encode_dict_end(edata)
 
#define TYPVAL_ENCODE_CONV_RECURSE(val, conv_type)   TYPVAL_ENCODE_CONV_NIL(val)
 
#define TYPVAL_ENCODE_SCOPE   static
 
#define TYPVAL_ENCODE_NAME   object
 
#define TYPVAL_ENCODE_FIRST_ARG_TYPE   EncodedData *const
 
#define TYPVAL_ENCODE_FIRST_ARG_NAME   edata
 

Functions

Object vim_to_object (typval_T *obj)
 
bool object_to_vim (Object obj, typval_T *tv, Error *err)
 

Macro Definition Documentation

◆ TYPVAL_ENCODE_ALLOW_SPECIALS

#define TYPVAL_ENCODE_ALLOW_SPECIALS   false

◆ TYPVAL_ENCODE_CONV_BLOB

#define TYPVAL_ENCODE_CONV_BLOB (   tv,
  blob,
  len 
)
Value:
do { \
const size_t len_ = (size_t)(len); \
const blob_T *const blob_ = (blob); \
kvi_push(edata->stack, STRING_OBJ(((String) { \
.data = len_ != 0 ? xmemdupz(blob_->bv_ga.ga_data, len_) : xstrdup(""), \
.size = len_ \
}))); \
} while (0)

◆ TYPVAL_ENCODE_CONV_BOOL

#define TYPVAL_ENCODE_CONV_BOOL (   tv,
  num 
)    kvi_push(edata->stack, BOOLEAN_OBJ((Boolean)(num)))

◆ TYPVAL_ENCODE_CONV_DICT_AFTER_KEY

#define TYPVAL_ENCODE_CONV_DICT_AFTER_KEY (   tv,
  dict 
)    typval_encode_after_key(edata)

◆ TYPVAL_ENCODE_CONV_DICT_BETWEEN_ITEMS

#define TYPVAL_ENCODE_CONV_DICT_BETWEEN_ITEMS (   tv,
  dict 
)    typval_encode_between_dict_items(edata)

◆ TYPVAL_ENCODE_CONV_DICT_END

#define TYPVAL_ENCODE_CONV_DICT_END (   tv,
  dict 
)    typval_encode_dict_end(edata)

◆ TYPVAL_ENCODE_CONV_DICT_START

#define TYPVAL_ENCODE_CONV_DICT_START (   tv,
  dict,
  len 
)    typval_encode_dict_start(edata, (size_t)(len))

◆ TYPVAL_ENCODE_CONV_EMPTY_DICT

#define TYPVAL_ENCODE_CONV_EMPTY_DICT (   tv,
  dict 
)
Value:
kvi_push(edata->stack, \
DICTIONARY_OBJ(((Dictionary) { .capacity = 0, .size = 0 })))

◆ TYPVAL_ENCODE_CONV_EMPTY_LIST

#define TYPVAL_ENCODE_CONV_EMPTY_LIST (   tv)    kvi_push(edata->stack, ARRAY_OBJ(((Array) { .capacity = 0, .size = 0 })))

◆ TYPVAL_ENCODE_CONV_EXT_STRING

#define TYPVAL_ENCODE_CONV_EXT_STRING (   tv,
  str,
  len,
  type 
)    TYPVAL_ENCODE_CONV_NIL(tv)

◆ TYPVAL_ENCODE_CONV_FLOAT

#define TYPVAL_ENCODE_CONV_FLOAT (   tv,
  flt 
)    kvi_push(edata->stack, FLOAT_OBJ((Float)(flt)))

◆ TYPVAL_ENCODE_CONV_FUNC_BEFORE_ARGS

#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_ARGS (   tv,
  len 
)

◆ TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF

#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF (   tv,
  len 
)

◆ TYPVAL_ENCODE_CONV_FUNC_END

#define TYPVAL_ENCODE_CONV_FUNC_END (   tv)

◆ TYPVAL_ENCODE_CONV_FUNC_START

#define TYPVAL_ENCODE_CONV_FUNC_START (   tv,
  fun 
)
Value:
do { \
ufunc_T *fp = find_func(fun); \
if (fp != NULL && fp->uf_cb == nlua_CFunction_func_call) { \
LuaRef ref = api_new_luaref(((LuaCFunctionState *)fp->uf_cb_state)->lua_callable.func_ref); \
kvi_push(edata->stack, LUAREF_OBJ(ref)); \
} else { \
TYPVAL_ENCODE_CONV_NIL(tv); \
} \
goto typval_encode_stop_converting_one_item; \
} while (0)

◆ TYPVAL_ENCODE_CONV_LIST_BETWEEN_ITEMS

#define TYPVAL_ENCODE_CONV_LIST_BETWEEN_ITEMS (   tv)    typval_encode_between_list_items(edata)

◆ TYPVAL_ENCODE_CONV_LIST_END

#define TYPVAL_ENCODE_CONV_LIST_END (   tv)    typval_encode_list_end(edata)

◆ TYPVAL_ENCODE_CONV_LIST_START

#define TYPVAL_ENCODE_CONV_LIST_START (   tv,
  len 
)    typval_encode_list_start(edata, (size_t)(len))

◆ TYPVAL_ENCODE_CONV_NIL

#define TYPVAL_ENCODE_CONV_NIL (   tv)    kvi_push(edata->stack, NIL)

◆ TYPVAL_ENCODE_CONV_NUMBER

#define TYPVAL_ENCODE_CONV_NUMBER (   tv,
  num 
)    kvi_push(edata->stack, INTEGER_OBJ((Integer)(num)))

◆ TYPVAL_ENCODE_CONV_REAL_DICT_AFTER_START

#define TYPVAL_ENCODE_CONV_REAL_DICT_AFTER_START (   tv,
  dict,
  mpsv 
)

◆ TYPVAL_ENCODE_CONV_REAL_LIST_AFTER_START

#define TYPVAL_ENCODE_CONV_REAL_LIST_AFTER_START (   tv,
  mpsv 
)

◆ TYPVAL_ENCODE_CONV_RECURSE

#define TYPVAL_ENCODE_CONV_RECURSE (   val,
  conv_type 
)    TYPVAL_ENCODE_CONV_NIL(val)

◆ TYPVAL_ENCODE_CONV_STR_STRING

#define TYPVAL_ENCODE_CONV_STR_STRING   TYPVAL_ENCODE_CONV_STRING

◆ TYPVAL_ENCODE_CONV_STRING

#define TYPVAL_ENCODE_CONV_STRING (   tv,
  str,
  len 
)
Value:
do { \
const size_t len_ = (size_t)(len); \
const char *const str_ = (const char *)(str); \
assert(len_ == 0 || str_ != NULL); \
kvi_push(edata->stack, STRING_OBJ(cbuf_to_string((len_?str_:""), len_))); \
} while (0)

◆ TYPVAL_ENCODE_CONV_UNSIGNED_NUMBER

#define TYPVAL_ENCODE_CONV_UNSIGNED_NUMBER   TYPVAL_ENCODE_CONV_NUMBER

◆ TYPVAL_ENCODE_FIRST_ARG_NAME

#define TYPVAL_ENCODE_FIRST_ARG_NAME   edata

◆ TYPVAL_ENCODE_FIRST_ARG_TYPE

#define TYPVAL_ENCODE_FIRST_ARG_TYPE   EncodedData *const

◆ TYPVAL_ENCODE_NAME

#define TYPVAL_ENCODE_NAME   object

◆ TYPVAL_ENCODE_SCOPE

#define TYPVAL_ENCODE_SCOPE   static

◆ TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK

#define TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK (   label,
  kv_pair 
)

Function Documentation

◆ object_to_vim()

bool object_to_vim ( Object  obj,
typval_T tv,
Error err 
)

Converts from type Object to a VimL value.

Parameters
objObject to convert from.
tvConversion result is placed here. On failure member v_type is set to VAR_UNKNOWN (no allocation was made for this variable). returns true if conversion is successful, otherwise false.

◆ vim_to_object()

Object vim_to_object ( typval_T obj)

Convert a vim object to an Object instance, recursively expanding Arrays/Dictionaries.

Parameters
objThe source object
Returns
The converted value
tv
typval_T tv
Definition: typval.c:1705
xstrdup
char * xstrdup(const char *str) FUNC_ATTR_MALLOC FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_RET FUNC_ATTR_NONNULL_ALL
Definition: memory.c:420
size
size_t size
Definition: regexp_nfa.c:5986
fp
FILE * fp
Definition: edit.c:3050
blobvar_S
Structure to hold info about a Blob.
Definition: typval.h:263
cbuf_to_string
String cbuf_to_string(const char *buf, size_t size) FUNC_ATTR_NONNULL_ALL
Definition: helpers.c:510
nlua_CFunction_func_call
int nlua_CFunction_func_call(int argcount, typval_T *argvars, typval_T *rettv, void *state)
Definition: executor.c:1678
kvi_push
#define kvi_push(v, x)
Definition: kvec.h:221
DICTIONARY_OBJ
#define DICTIONARY_OBJ(d)
Definition: helpers.h:49
STRING_OBJ
#define STRING_OBJ(s)
Definition: helpers.h:27
LUAREF_OBJ
#define LUAREF_OBJ(r)
Definition: helpers.h:53
String
Definition: defs.h:77
Dictionary
Definition: defs.h:95
api_new_luaref
LuaRef api_new_luaref(LuaRef original_ref)
Definition: executor.c:1120
find_func
ufunc_T * find_func(const char_u *name)
Definition: userfunc.c:549
xmemdupz
void * xmemdupz(const void *data, size_t len) FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
Definition: memory.c:201
LuaCFunctionState
Definition: converter.h:16
NULL
return NULL
Definition: eval.c:9968
len
int len
Definition: helpers.c:1105