aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval/typval.h
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2016-08-21 00:20:01 +0300
committerZyX <kp-pav@yandex.ru>2017-03-29 10:07:43 +0300
commit5cdf7177ec71e4b9b3295ead93bedf7ff226a2b2 (patch)
treec8ad8b61d42f667790cc3edae529e762e0e2ec13 /src/nvim/eval/typval.h
parent2dcfc439b2ec2be4d830826061e89860977516be (diff)
downloadrneovim-5cdf7177ec71e4b9b3295ead93bedf7ff226a2b2.tar.gz
rneovim-5cdf7177ec71e4b9b3295ead93bedf7ff226a2b2.tar.bz2
rneovim-5cdf7177ec71e4b9b3295ead93bedf7ff226a2b2.zip
eval: Move get_float_arg to typval.h
Assuming `inline` is there for a reason, so it is kept and function was moved to typval.h and not to typval.c which does not have problems with #including message.h.
Diffstat (limited to 'src/nvim/eval/typval.h')
-rw-r--r--src/nvim/eval/typval.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/nvim/eval/typval.h b/src/nvim/eval/typval.h
index 6929e37e43..0eef2ddaac 100644
--- a/src/nvim/eval/typval.h
+++ b/src/nvim/eval/typval.h
@@ -13,6 +13,7 @@
#include "nvim/lib/queue.h"
#include "nvim/profile.h" // for proftime_T
#include "nvim/pos.h" // for linenr_T
+#include "nvim/gettext.h"
/// Type used for VimL VAR_NUMBER values
typedef int varnumber_T;
@@ -370,6 +371,32 @@ extern bool tv_in_free_unref_items;
} \
})
+static inline bool tv_get_float(const typval_T *const tv, float_T *const ret_f)
+ REAL_FATTR_NONNULL_ALL REAL_FATTR_WARN_UNUSED_RESULT;
+
+// FIXME circular dependency, cannot import message.h.
+bool emsgf(const char *const fmt, ...);
+
+/// Get the float value
+///
+/// @param[in] tv VimL object to get value from.
+/// @param[out] ret_f Location where resulting float is stored.
+///
+/// @return true in case of success, false if tv is not a number or float.
+static inline bool tv_get_float(const typval_T *const tv, float_T *const ret_f)
+{
+ if (tv->v_type == VAR_FLOAT) {
+ *ret_f = tv->vval.v_float;
+ return true;
+ }
+ if (tv->v_type == VAR_NUMBER) {
+ *ret_f = (float_T)tv->vval.v_number;
+ return true;
+ }
+ emsgf(_("E808: Number or Float required"));
+ return false;
+}
+
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "eval/typval.h.generated.h"
#endif