From 94b068a40fa24343b08faef60c2ab76862891f04 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Thu, 29 Nov 2012 17:52:52 +0100 Subject: [PATCH] Use better method names and add comments --- simgear/nasal/cppbind/Ghost.hxx | 16 ++++++++++++++-- simgear/nasal/cppbind/cppbind_test.cxx | 6 +++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/simgear/nasal/cppbind/Ghost.hxx b/simgear/nasal/cppbind/Ghost.hxx index 6a8ccfb8..cfb6a960 100644 --- a/simgear/nasal/cppbind/Ghost.hxx +++ b/simgear/nasal/cppbind/Ghost.hxx @@ -229,8 +229,16 @@ namespace nasal args(args) {} + /** + * Get the argument with given index if it exists. Otherwise returns the + * passed default value. + * + * @tparam T Type of argument (converted using ::from_nasal) + * @param index Index of requested argument + * @param def Default value returned if too few arguments available + */ template - T get(size_t index, const T& def = T()) const + T getArg(size_t index, const T& def = T()) const { if( index >= argc ) return def; @@ -238,8 +246,12 @@ namespace nasal return from_nasal(c, args[index]); } + /** + * Get the argument with given index. Raises a Nasal runtime error if there + * are to few arguments available. + */ template - T require(size_t index) const + T requireArg(size_t index) const { if( index >= argc ) naRuntimeError(c, "Missing required arg #%d", index); diff --git a/simgear/nasal/cppbind/cppbind_test.cxx b/simgear/nasal/cppbind/cppbind_test.cxx index 0f0caedf..1ff01973 100644 --- a/simgear/nasal/cppbind/cppbind_test.cxx +++ b/simgear/nasal/cppbind/cppbind_test.cxx @@ -157,9 +157,9 @@ int main(int argc, char* argv[]) to_nasal(c, std::string("test-arg")) }; CallContext cc(c, sizeof(args)/sizeof(args[0]), args); - VERIFY( cc.require(0) == "test-arg" ); - VERIFY( cc.get(0) == "test-arg" ); - VERIFY( cc.get(1) == "" ); + VERIFY( cc.requireArg(0) == "test-arg" ); + VERIFY( cc.getArg(0) == "test-arg" ); + VERIFY( cc.getArg(1) == "" ); // TODO actually do something with the ghosts...