From dfdd1c6d5e97e930b5ff260b16310806a6cd8225 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Thu, 29 May 2014 16:29:02 +0200 Subject: [PATCH] cppbind: some new methods and safer type check. --- simgear/nasal/cppbind/NasalCallContext.hxx | 38 +++++++++------------- simgear/nasal/cppbind/NasalHash.hxx | 2 +- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/simgear/nasal/cppbind/NasalCallContext.hxx b/simgear/nasal/cppbind/NasalCallContext.hxx index 0e5be166..574fe59e 100644 --- a/simgear/nasal/cppbind/NasalCallContext.hxx +++ b/simgear/nasal/cppbind/NasalCallContext.hxx @@ -38,30 +38,24 @@ namespace nasal args(args) {} - bool isNumeric(size_t index) const - { - return (index < argc && naIsNum(args[index])); - } - - bool isString(size_t index) const - { - return (index < argc && naIsString(args[index])); - } - - bool isHash(size_t index) const - { - return (index < argc && naIsHash(args[index])); - } - - bool isVector(size_t index) const - { - return (index < argc && naIsVector(args[index])); +#define SG_CTX_CHECK_ARG(name, check)\ + bool is##name(size_t index) const\ + {\ + return (index < argc && naIs##check(args[index]));\ } - bool isGhost(size_t index) const - { - return (index < argc && naIsGhost(args[index])); - } + SG_CTX_CHECK_ARG(Code, Code) + SG_CTX_CHECK_ARG(CCode, CCode) + SG_CTX_CHECK_ARG(Func, Func) + SG_CTX_CHECK_ARG(Ghost, Ghost) + SG_CTX_CHECK_ARG(Hash, Hash) + SG_CTX_CHECK_ARG(Nil, Nil) + SG_CTX_CHECK_ARG(Numeric, Num) + SG_CTX_CHECK_ARG(Scalar, Scalar) + SG_CTX_CHECK_ARG(String, String) + SG_CTX_CHECK_ARG(Vector, Vector) + +#undef SG_CTX_CHECK_ARG void popFront(size_t num = 1) { diff --git a/simgear/nasal/cppbind/NasalHash.hxx b/simgear/nasal/cppbind/NasalHash.hxx index aaf673dd..af3b8fae 100644 --- a/simgear/nasal/cppbind/NasalHash.hxx +++ b/simgear/nasal/cppbind/NasalHash.hxx @@ -183,7 +183,7 @@ namespace nasal _key(key) { assert(hash); - assert(!naIsNil(key)); + assert(naIsScalar(key)); } std::string getKey() const -- 2.39.5