aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2014-05-16 10:21:30 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-05-17 08:05:44 -0300
commit76a2fb5667461a8b7fa1abfb5a2c7381ced3f519 (patch)
treec5f06f37b7019107b9f70f24b5eb9951a5619e17 /src/nvim/api
parenta8b0c9e576e9c0155546b03944314449d3f1a5c3 (diff)
downloadrneovim-76a2fb5667461a8b7fa1abfb5a2c7381ced3f519.tar.gz
rneovim-76a2fb5667461a8b7fa1abfb5a2c7381ced3f519.tar.bz2
rneovim-76a2fb5667461a8b7fa1abfb5a2c7381ced3f519.zip
Use more descriptive names for API primitive types
Instead of exposing native C types to a public API that can be consumed by other platforms, we are now using the following translation: int64_t -> Integer double -> Float bool -> Boolean
Diffstat (limited to 'src/nvim/api')
-rw-r--r--src/nvim/api/buffer.c30
-rw-r--r--src/nvim/api/buffer.h30
-rw-r--r--src/nvim/api/defs.h23
-rw-r--r--src/nvim/api/helpers.c18
-rw-r--r--src/nvim/api/tabpage.c6
-rw-r--r--src/nvim/api/tabpage.h4
-rw-r--r--src/nvim/api/vim.c8
-rw-r--r--src/nvim/api/vim.h8
-rw-r--r--src/nvim/api/window.c10
-rw-r--r--src/nvim/api/window.h10
10 files changed, 76 insertions, 71 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index f41e9a73fe..d3bec718aa 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -40,7 +40,7 @@ static void fix_cursor(linenr_T lo, linenr_T hi, linenr_T extra);
// Normalizes 0-based indexes to buffer line numbers
static int64_t normalize_index(buf_T *buf, int64_t index);
-int64_t buffer_get_length(Buffer buffer, Error *err)
+Integer buffer_get_length(Buffer buffer, Error *err)
{
buf_T *buf = find_buffer(buffer, err);
@@ -51,7 +51,7 @@ int64_t buffer_get_length(Buffer buffer, Error *err)
return buf->b_ml.ml_line_count;
}
-String buffer_get_line(Buffer buffer, int64_t index, Error *err)
+String buffer_get_line(Buffer buffer, Integer index, Error *err)
{
String rv = {.size = 0};
StringArray slice = buffer_get_slice(buffer, index, index, true, true, err);
@@ -63,23 +63,23 @@ String buffer_get_line(Buffer buffer, int64_t index, Error *err)
return rv;
}
-void buffer_set_line(Buffer buffer, int64_t index, String line, Error *err)
+void buffer_set_line(Buffer buffer, Integer index, String line, Error *err)
{
StringArray array = {.items = &line, .size = 1};
buffer_set_slice(buffer, index, index, true, true, array, err);
}
-void buffer_del_line(Buffer buffer, int64_t index, Error *err)
+void buffer_del_line(Buffer buffer, Integer index, Error *err)
{
StringArray array = {.size = 0};
buffer_set_slice(buffer, index, index, true, true, array, err);
}
StringArray buffer_get_slice(Buffer buffer,
- int64_t start,
- int64_t end,
- bool include_start,
- bool include_end,
+ Integer start,
+ Integer end,
+ Boolean include_start,
+ Boolean include_end,
Error *err)
{
StringArray rv = {.size = 0};
@@ -109,10 +109,10 @@ StringArray buffer_get_slice(Buffer buffer,
}
void buffer_set_slice(Buffer buffer,
- int64_t start,
- int64_t end,
- bool include_start,
- bool include_end,
+ Integer start,
+ Integer end,
+ Boolean include_start,
+ Boolean include_end,
StringArray replacement,
Error *err)
{
@@ -310,15 +310,15 @@ void buffer_set_name(Buffer buffer, String name, Error *err)
}
}
-bool buffer_is_valid(Buffer buffer)
+Boolean buffer_is_valid(Buffer buffer)
{
Error stub = {.set = false};
return find_buffer(buffer, &stub) != NULL;
}
-void buffer_insert(Buffer buffer, int64_t index, StringArray lines, Error *err)
+void buffer_insert(Buffer buffer, Integer lnum, StringArray lines, Error *err)
{
- buffer_set_slice(buffer, index, index, false, true, lines, err);
+ buffer_set_slice(buffer, lnum, lnum, false, true, lines, err);
}
Position buffer_get_mark(Buffer buffer, String name, Error *err)
diff --git a/src/nvim/api/buffer.h b/src/nvim/api/buffer.h
index 59370b3c18..5f39589679 100644
--- a/src/nvim/api/buffer.h
+++ b/src/nvim/api/buffer.h
@@ -11,7 +11,7 @@
/// @param buffer The buffer handle
/// @param[out] err Details of an error that may have occurred
/// @return The line count
-int64_t buffer_get_length(Buffer buffer, Error *err);
+Integer buffer_get_length(Buffer buffer, Error *err);
/// Gets a buffer line
///
@@ -19,7 +19,7 @@ int64_t buffer_get_length(Buffer buffer, Error *err);
/// @param index The line index
/// @param[out] err Details of an error that may have occurred
/// @return The line string
-String buffer_get_line(Buffer buffer, int64_t index, Error *err);
+String buffer_get_line(Buffer buffer, Integer index, Error *err);
/// Sets a buffer line
///
@@ -27,14 +27,14 @@ String buffer_get_line(Buffer buffer, int64_t index, Error *err);
/// @param index The line index
/// @param line The new line.
/// @param[out] err Details of an error that may have occurred
-void buffer_set_line(Buffer buffer, int64_t index, String line, Error *err);
+void buffer_set_line(Buffer buffer, Integer index, String line, Error *err);
/// Deletes a buffer line
///
/// @param buffer The buffer handle
/// @param index The line index
/// @param[out] err Details of an error that may have occurred
-void buffer_del_line(Buffer buffer, int64_t index, Error *err);
+void buffer_del_line(Buffer buffer, Integer index, Error *err);
/// Retrieves a line range from the buffer
///
@@ -46,10 +46,10 @@ void buffer_del_line(Buffer buffer, int64_t index, Error *err);
/// @param[out] err Details of an error that may have occurred
/// @return An array of lines
StringArray buffer_get_slice(Buffer buffer,
- int64_t start,
- int64_t end,
- bool include_start,
- bool include_end,
+ Integer start,
+ Integer end,
+ Boolean include_start,
+ Boolean include_end,
Error *err);
/// Replaces a line range on the buffer
@@ -63,10 +63,10 @@ StringArray buffer_get_slice(Buffer buffer,
/// will simply delete the line range)
/// @param[out] err Details of an error that may have occurred
void buffer_set_slice(Buffer buffer,
- int64_t start,
- int64_t end,
- bool include_start,
- bool include_end,
+ Integer start,
+ Integer end,
+ Boolean include_start,
+ Boolean include_end,
StringArray replacement,
Error *err);
@@ -122,16 +122,16 @@ void buffer_set_name(Buffer buffer, String name, Error *err);
///
/// @param buffer The buffer handle
/// @return true if the buffer is valid, false otherwise
-bool buffer_is_valid(Buffer buffer);
+Boolean buffer_is_valid(Buffer buffer);
/// Inserts a sequence of lines to a buffer at a certain index
///
/// @param buffer The buffer handle
-/// @param lnum Insert the lines before `lnum`. If negative, it will append
+/// @param lnum Insert the lines after `lnum`. If negative, it will append
/// to the end of the buffer.
/// @param lines An array of lines
/// @param[out] err Details of an error that may have occurred
-void buffer_insert(Buffer buffer, int64_t index, StringArray lines, Error *err);
+void buffer_insert(Buffer buffer, Integer lnum, StringArray lines, Error *err);
/// Return a tuple (row,col) representing the position of the named mark
///
diff --git a/src/nvim/api/defs.h b/src/nvim/api/defs.h
index 914ff3c5d5..3ee50310fb 100644
--- a/src/nvim/api/defs.h
+++ b/src/nvim/api/defs.h
@@ -2,6 +2,7 @@
#define NVIM_API_DEFS_H
#include <stdint.h>
+#include <stdbool.h>
#include <string.h>
// Basic types
@@ -10,14 +11,18 @@ typedef struct {
bool set;
} Error;
+typedef bool Boolean;
+typedef int64_t Integer;
+typedef double Float;
+
typedef struct {
char *data;
size_t size;
} String;
-typedef int64_t Buffer;
-typedef int64_t Window;
-typedef int64_t Tabpage;
+typedef Integer Buffer;
+typedef Integer Window;
+typedef Integer Tabpage;
typedef struct object Object;
@@ -27,7 +32,7 @@ typedef struct {
} StringArray;
typedef struct {
- int64_t row, col;
+ Integer row, col;
} Position;
typedef struct {
@@ -44,8 +49,8 @@ typedef struct {
typedef enum {
kObjectTypeNil,
- kObjectTypeBool,
- kObjectTypeInt,
+ kObjectTypeBoolean,
+ kObjectTypeInteger,
kObjectTypeFloat,
kObjectTypeString,
kObjectTypeArray,
@@ -55,9 +60,9 @@ typedef enum {
struct object {
ObjectType type;
union {
- bool boolean;
- int64_t integer;
- double floating_point;
+ Boolean boolean;
+ Integer integer;
+ Float floating;
String string;
Array array;
Dictionary dictionary;
diff --git a/src/nvim/api/helpers.c b/src/nvim/api/helpers.c
index 2f79bebeef..ea24e96a21 100644
--- a/src/nvim/api/helpers.c
+++ b/src/nvim/api/helpers.c
@@ -190,10 +190,10 @@ Object get_option_from(void *from, int type, String name, Error *err)
}
if (flags & SOPT_BOOL) {
- rv.type = kObjectTypeBool;
+ rv.type = kObjectTypeBoolean;
rv.data.boolean = numval ? true : false;
} else if (flags & SOPT_NUM) {
- rv.type = kObjectTypeInt;
+ rv.type = kObjectTypeInteger;
rv.data.integer = numval;
} else if (flags & SOPT_STRING) {
if (stringval) {
@@ -242,7 +242,7 @@ void set_option_to(void *to, int type, String name, Object value, Error *err)
int opt_flags = (type ? OPT_LOCAL : OPT_GLOBAL);
if (flags & SOPT_BOOL) {
- if (value.type != kObjectTypeBool) {
+ if (value.type != kObjectTypeBoolean) {
set_api_error("option requires a boolean value", err);
goto cleanup;
}
@@ -250,7 +250,7 @@ void set_option_to(void *to, int type, String name, Object value, Error *err)
set_option_value_for(key, val, NULL, opt_flags, type, to, err);
} else if (flags & SOPT_NUM) {
- if (value.type != kObjectTypeInt) {
+ if (value.type != kObjectTypeInteger) {
set_api_error("option requires an integer value", err);
goto cleanup;
}
@@ -330,19 +330,19 @@ static bool object_to_vim(Object obj, typval_T *tv, Error *err)
tv->vval.v_number = 0;
break;
- case kObjectTypeBool:
+ case kObjectTypeBoolean:
tv->v_type = VAR_NUMBER;
tv->vval.v_number = obj.data.boolean;
break;
- case kObjectTypeInt:
+ case kObjectTypeInteger:
tv->v_type = VAR_NUMBER;
tv->vval.v_number = obj.data.integer;
break;
case kObjectTypeFloat:
tv->v_type = VAR_FLOAT;
- tv->vval.v_float = obj.data.floating_point;
+ tv->vval.v_float = obj.data.floating;
break;
case kObjectTypeString:
@@ -431,13 +431,13 @@ static Object vim_to_object_rec(typval_T *obj, khash_t(Lookup) *lookup)
break;
case VAR_NUMBER:
- rv.type = kObjectTypeInt;
+ rv.type = kObjectTypeInteger;
rv.data.integer = obj->vval.v_number;
break;
case VAR_FLOAT:
rv.type = kObjectTypeFloat;
- rv.data.floating_point = obj->vval.v_float;
+ rv.data.floating = obj->vval.v_float;
break;
case VAR_LIST:
diff --git a/src/nvim/api/tabpage.c b/src/nvim/api/tabpage.c
index c577453b37..fc50723ba5 100644
--- a/src/nvim/api/tabpage.c
+++ b/src/nvim/api/tabpage.c
@@ -7,9 +7,9 @@
#include "nvim/api/defs.h"
#include "nvim/api/helpers.h"
-int64_t tabpage_get_window_count(Tabpage tabpage, Error *err)
+Integer tabpage_get_window_count(Tabpage tabpage, Error *err)
{
- uint64_t rv = 0;
+ Integer rv = 0;
tabpage_T *tab = find_tab(tabpage, err);
if (!tab) {
@@ -80,7 +80,7 @@ Window tabpage_get_window(Tabpage tabpage, Error *err)
}
}
-bool tabpage_is_valid(Tabpage tabpage)
+Boolean tabpage_is_valid(Tabpage tabpage)
{
Error stub = {.set = false};
return find_tab(tabpage, &stub) != NULL;
diff --git a/src/nvim/api/tabpage.h b/src/nvim/api/tabpage.h
index 54ed70a6f6..ef049fb644 100644
--- a/src/nvim/api/tabpage.h
+++ b/src/nvim/api/tabpage.h
@@ -11,7 +11,7 @@
/// @param tabpage The tabpage
/// @param[out] err Details of an error that may have occurred
/// @return The number of windows in `tabpage`
-int64_t tabpage_get_window_count(Tabpage tabpage, Error *err);
+Integer tabpage_get_window_count(Tabpage tabpage, Error *err);
/// Gets a tabpage variable
///
@@ -41,7 +41,7 @@ Window tabpage_get_window(Tabpage tabpage, Error *err);
///
/// @param tabpage The tab page handle
/// @return true if the tab page is valid, false otherwise
-bool tabpage_is_valid(Tabpage tabpage);
+Boolean tabpage_is_valid(Tabpage tabpage);
#endif // NVIM_API_TABPAGE_H
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index 44f805ed38..bdd48336d1 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -66,7 +66,7 @@ Object vim_eval(String str, Error *err)
return rv;
}
-int64_t vim_strwidth(String str)
+Integer vim_strwidth(String str)
{
return mb_string2cells((char_u *)str.data, str.size);
}
@@ -177,7 +177,7 @@ void vim_err_write(String str)
write_msg(str, true);
}
-int64_t vim_get_buffer_count(void)
+Integer vim_get_buffer_count(void)
{
buf_T *b = firstbuf;
uint64_t n = 0;
@@ -212,7 +212,7 @@ void vim_set_current_buffer(Buffer buffer, Error *err)
try_end(err);
}
-int64_t vim_get_window_count(void)
+Integer vim_get_window_count(void)
{
tabpage_T *tp;
win_T *wp;
@@ -265,7 +265,7 @@ void vim_set_current_window(Window window, Error *err)
try_end(err);
}
-int64_t vim_get_tabpage_count(void)
+Integer vim_get_tabpage_count(void)
{
tabpage_T *tp = first_tabpage;
uint64_t rv = 0;
diff --git a/src/nvim/api/vim.h b/src/nvim/api/vim.h
index 3db9d4d6f6..17a17c28c7 100644
--- a/src/nvim/api/vim.h
+++ b/src/nvim/api/vim.h
@@ -31,7 +31,7 @@ Object vim_eval(String str, Error *err);
///
/// @param str Some text
/// @return The number of cells
-int64_t vim_strwidth(String str);
+Integer vim_strwidth(String str);
/// Returns a list of paths contained in 'runtimepath'
///
@@ -110,7 +110,7 @@ void vim_err_write(String str);
/// Gets the number of buffers
///
/// @return The number of buffers
-int64_t vim_get_buffer_count(void);
+Integer vim_get_buffer_count(void);
/// Return the current buffer
///
@@ -126,7 +126,7 @@ void vim_set_current_buffer(Buffer buffer, Error *err);
/// Gets the number of windows
///
/// @return The number of windows
-int64_t vim_get_window_count(void);
+Integer vim_get_window_count(void);
/// Return the current window
///
@@ -141,7 +141,7 @@ void vim_set_current_window(Window window, Error *err);
/// Gets the number of tab pages
///
/// @return The number of tab pages
-int64_t vim_get_tabpage_count(void);
+Integer vim_get_tabpage_count(void);
/// Return the current tab page
///
diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c
index 7196d949bb..b0d2838640 100644
--- a/src/nvim/api/window.c
+++ b/src/nvim/api/window.c
@@ -56,7 +56,7 @@ void window_set_cursor(Window window, Position pos, Error *err)
update_screen(VALID);
}
-int64_t window_get_height(Window window, Error *err)
+Integer window_get_height(Window window, Error *err)
{
win_T *win = find_window(window, err);
@@ -67,7 +67,7 @@ int64_t window_get_height(Window window, Error *err)
return win->w_height;
}
-void window_set_height(Window window, int64_t height, Error *err)
+void window_set_height(Window window, Integer height, Error *err)
{
win_T *win = find_window(window, err);
@@ -83,7 +83,7 @@ void window_set_height(Window window, int64_t height, Error *err)
try_end(err);
}
-int64_t window_get_width(Window window, Error *err)
+Integer window_get_width(Window window, Error *err)
{
win_T *win = find_window(window, err);
@@ -94,7 +94,7 @@ int64_t window_get_width(Window window, Error *err)
return win->w_width;
}
-void window_set_width(Window window, int64_t width, Error *err)
+void window_set_width(Window window, Integer width, Error *err)
{
win_T *win = find_window(window, err);
@@ -176,7 +176,7 @@ Tabpage window_get_tabpage(Window window, Error *err)
return 0;
}
-bool window_is_valid(Window window)
+Boolean window_is_valid(Window window)
{
Error stub = {.set = false};
return find_window(window, &stub) != NULL;
diff --git a/src/nvim/api/window.h b/src/nvim/api/window.h
index f0e485884a..525b7f86c7 100644
--- a/src/nvim/api/window.h
+++ b/src/nvim/api/window.h
@@ -32,7 +32,7 @@ void window_set_cursor(Window window, Position pos, Error *err);
/// @param window The window handle
/// @param[out] err Details of an error that may have occurred
/// @return the height in rows
-int64_t window_get_height(Window window, Error *err);
+Integer window_get_height(Window window, Error *err);
/// Sets the window height. This will only succeed if the screen is split
/// horizontally.
@@ -40,14 +40,14 @@ int64_t window_get_height(Window window, Error *err);
/// @param window The window handle
/// @param height the new height in rows
/// @param[out] err Details of an error that may have occurred
-void window_set_height(Window window, int64_t height, Error *err);
+void window_set_height(Window window, Integer height, Error *err);
/// Gets the window width
///
/// @param window The window handle
/// @param[out] err Details of an error that may have occurred
/// @return the width in columns
-int64_t window_get_width(Window window, Error *err);
+Integer window_get_width(Window window, Error *err);
/// Sets the window width. This will only succeed if the screen is split
/// vertically.
@@ -55,7 +55,7 @@ int64_t window_get_width(Window window, Error *err);
/// @param window The window handle
/// @param width the new width in columns
/// @param[out] err Details of an error that may have occurred
-void window_set_width(Window window, int64_t width, Error *err);
+void window_set_width(Window window, Integer width, Error *err);
/// Gets a window variable
///
@@ -109,7 +109,7 @@ Tabpage window_get_tabpage(Window window, Error *err);
///
/// @param window The window handle
/// @return true if the window is valid, false otherwise
-bool window_is_valid(Window window);
+Boolean window_is_valid(Window window);
#endif // NVIM_API_WINDOW_H