diff --git a/simgear/nasal/cppbind/Ghost.hxx b/simgear/nasal/cppbind/Ghost.hxx index c1875bf6..bab88891 100644 --- a/simgear/nasal/cppbind/Ghost.hxx +++ b/simgear/nasal/cppbind/Ghost.hxx @@ -770,7 +770,7 @@ namespace nasal /** * Register anything that accepts an object instance and a - * nasal::CallContext whith automatic conversion of the return type to + * nasal::CallContext with automatic conversion of the return type to * Nasal. * * @code{cpp} @@ -1148,7 +1148,7 @@ namespace nasal const CallContext& ctx ) { - return (*to_nasal_ptr::get())(ctx.c, func(obj, ctx)); + return (*to_nasal_ptr::get())(ctx.c_ctx(), func(obj, ctx)); }; /** diff --git a/simgear/nasal/cppbind/NasalCallContext.hxx b/simgear/nasal/cppbind/NasalCallContext.hxx index ea4e1967..a7781eac 100644 --- a/simgear/nasal/cppbind/NasalCallContext.hxx +++ b/simgear/nasal/cppbind/NasalCallContext.hxx @@ -20,8 +20,7 @@ #ifndef SG_NASAL_CALL_CONTEXT_HXX_ #define SG_NASAL_CALL_CONTEXT_HXX_ -#include "from_nasal.hxx" -#include "to_nasal.hxx" +#include "NasalContext.hxx" namespace nasal { @@ -29,11 +28,12 @@ namespace nasal /** * Context passed to a function/method being called from Nasal */ - class CallContext + class CallContext: + public ContextWrapper { public: CallContext(naContext c, naRef me, size_t argc, naRef* args): - c(c), + ContextWrapper(c), me(me), argc(argc), args(args) @@ -102,28 +102,14 @@ namespace nasal requireArg(size_t index) const { if( index >= argc ) - naRuntimeError(c, "Missing required arg #%d", index); + runtimeError("Missing required arg #%d", index); return from_nasal(args[index]); } - template - naRef to_nasal(T arg) const - { - return nasal::to_nasal(c, arg); - } - - template - typename from_nasal_ptr::return_type - from_nasal(naRef ref) const - { - return (*from_nasal_ptr::get())(c, ref); - } - - naContext c; - naRef me; - size_t argc; - naRef *args; + naRef me; + size_t argc; + naRef *args; }; } // namespace nasal diff --git a/simgear/nasal/cppbind/NasalContext.cxx b/simgear/nasal/cppbind/NasalContext.cxx index d2a82d88..fe0e4755 100644 --- a/simgear/nasal/cppbind/NasalContext.cxx +++ b/simgear/nasal/cppbind/NasalContext.cxx @@ -17,13 +17,59 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA #include "NasalContext.hxx" +#include "NasalHash.hxx" +#include "NasalString.hxx" + +#include namespace nasal { + //---------------------------------------------------------------------------- + ContextWrapper::ContextWrapper(naContext ctx): + _ctx(ctx) + { + assert(_ctx); + } + + //---------------------------------------------------------------------------- + ContextWrapper::operator naContext() + { + return _ctx; + } + + //---------------------------------------------------------------------------- + naContext ContextWrapper::c_ctx() const + { + return const_cast(_ctx); + } + + //---------------------------------------------------------------------------- + Hash ContextWrapper::newHash() + { + return Hash(_ctx); + } + + //---------------------------------------------------------------------------- + String ContextWrapper::newString(const char* str) + { + return String(_ctx, str); + } + + //---------------------------------------------------------------------------- + naRef ContextWrapper::newVector(std::initializer_list vals) + { + naRef vec = naNewVector(_ctx); + naVec_setsize(_ctx, vec, vals.size()); + int i = 0; + for(naRef val: vals) + naVec_set(vec, i++, val); + return vec; + } + //---------------------------------------------------------------------------- Context::Context(): - _ctx(naNewContext()) + ContextWrapper(naNewContext()) { } @@ -32,18 +78,7 @@ namespace nasal Context::~Context() { naFreeContext(_ctx); - } - - //---------------------------------------------------------------------------- - Context::operator naContext() - { - return _ctx; - } - - //---------------------------------------------------------------------------- - Hash Context::newHash() - { - return Hash(_ctx); + _ctx = nullptr; } } // namespace nasal diff --git a/simgear/nasal/cppbind/NasalContext.hxx b/simgear/nasal/cppbind/NasalContext.hxx index c5e8e56c..e9379c9f 100644 --- a/simgear/nasal/cppbind/NasalContext.hxx +++ b/simgear/nasal/cppbind/NasalContext.hxx @@ -19,26 +19,83 @@ #ifndef SG_NASAL_CONTEXT_HXX_ #define SG_NASAL_CONTEXT_HXX_ -#include "NasalHash.hxx" +#include "from_nasal.hxx" +#include "to_nasal.hxx" namespace nasal { + class Hash; + class String; /** - * Manage lifetime and encapsulate a Nasal context. + * Wraps a nasal ::naContext without taking ownership/managing its lifetime */ - class Context + class ContextWrapper + { + public: + explicit ContextWrapper(naContext ctx); + + operator naContext(); + + /** Convert to non-const ::naContext for usage with C-APIs */ + naContext c_ctx() const; + + Hash newHash(); + String newString(const char* str); + + /** Create a new nasal vector and fill it with the given values */ + template + naRef newVector(Vals ... vals) + { + return newVector({to_nasal(vals)...}); + } + + /** Raise a nasal runtime error */ + template + void runtimeError(const char* fmt, Args ... args) const + { + naRuntimeError(c_ctx(), fmt, args...); + } + + template + naRef to_nasal(T arg) const + { + return nasal::to_nasal(_ctx, arg); + } + + template + naRef to_nasal(const T(&array)[N]) const + { + return nasal::to_nasal(_ctx, array); + } + + template + typename from_nasal_ptr::return_type + from_nasal(naRef ref) const + { + return (*from_nasal_ptr::get())(_ctx, ref); + } + + protected: + naContext _ctx; + + // Not exposed to avoid confusion of intializer_list to variadic + // arguments + naRef newVector(std::initializer_list vals); + }; + + /** + * Creates and manages the lifetime of a ::naContext + */ + class Context: + public ContextWrapper { public: Context(); ~Context(); - operator naContext(); - - Hash newHash(); - - protected: - naContext _ctx; + Context(const Context&) = delete; + Context& operator=(const Context&) = delete; }; } // namespace nasal diff --git a/simgear/nasal/cppbind/NasalString.hxx b/simgear/nasal/cppbind/NasalString.hxx index 81153f23..4e593aab 100644 --- a/simgear/nasal/cppbind/NasalString.hxx +++ b/simgear/nasal/cppbind/NasalString.hxx @@ -47,7 +47,7 @@ namespace nasal * * @param str Existing Nasal String */ - String(naRef str); + explicit String(naRef str); const char* c_str() const; const char* begin() const; diff --git a/simgear/nasal/cppbind/detail/from_nasal_helper.hxx b/simgear/nasal/cppbind/detail/from_nasal_helper.hxx index ecfeb2ff..3cf03dd2 100644 --- a/simgear/nasal/cppbind/detail/from_nasal_helper.hxx +++ b/simgear/nasal/cppbind/detail/from_nasal_helper.hxx @@ -84,7 +84,7 @@ namespace nasal { naRef _ref; - Me(naRef ref): + Me(naRef ref = naNil()): _ref(ref) {} diff --git a/simgear/nasal/cppbind/test/TestContext.hxx b/simgear/nasal/cppbind/test/TestContext.hxx index 69c2113e..5a90d590 100644 --- a/simgear/nasal/cppbind/test/TestContext.hxx +++ b/simgear/nasal/cppbind/test/TestContext.hxx @@ -20,50 +20,29 @@ #ifndef SG_NASAL_TESTCONTEXT_HXX_ #define SG_NASAL_TESTCONTEXT_HXX_ -#include +#include class TestContext: - public nasal::CallContext + public nasal::Context { public: - TestContext(): - CallContext(naNewContext(), naNil(), 0, 0) - {} - - ~TestContext() - { - naFreeContext(c); - } - void runGC() { - naFreeContext(c); + naFreeContext(_ctx); naGC(); - c = naNewContext(); + _ctx = naNewContext(); } - template - T from_str(const std::string& str) + template + T exec(const std::string& code, nasal::Me me) { - return from_nasal(to_nasal(str)); + return from_nasal(execImpl(code, me)); } - naRef exec(const std::string& code_str, nasal::Me me) - { - int err_line = -1; - naRef code = naParseCode( c, to_nasal(""), 0, - (char*)code_str.c_str(), code_str.length(), - &err_line ); - if( !naIsCode(code) ) - throw std::runtime_error("Failed to parse code: " + code_str); - - return naCallMethod(code, me, 0, 0, naNil()); - } - - template + template T exec(const std::string& code) { - return from_nasal(exec(code, naNil())); + return from_nasal(execImpl(code, {})); } template @@ -71,6 +50,26 @@ class TestContext: { return from_nasal(to_nasal(str)); } + + protected: + naRef execImpl(const std::string& code_str, nasal::Me me) + { + int err_line = -1; + naRef code = naParseCode( _ctx, to_nasal(""), 0, + (char*)code_str.c_str(), code_str.length(), + &err_line ); + if( !naIsCode(code) ) + throw std::runtime_error("Failed to parse code: " + code_str); + + naRef ret = naCallMethod(code, me, 0, 0, naNil()); + + if( char* err = naGetError(_ctx) ) + throw std::runtime_error( + "Failed to executed code: " + std::string(err) + ); + + return ret; + } }; #endif /* SG_NASAL_TESTCONTEXT_HXX_ */ diff --git a/simgear/nasal/cppbind/test/cppbind_test.cxx b/simgear/nasal/cppbind/test/cppbind_test.cxx index b4371f18..397c4e35 100644 --- a/simgear/nasal/cppbind/test/cppbind_test.cxx +++ b/simgear/nasal/cppbind/test/cppbind_test.cxx @@ -1,6 +1,8 @@ #define BOOST_TEST_MODULE cppbind #include +#include "TestContext.hxx" + #include #include #include @@ -117,42 +119,42 @@ naRef f_freeFunction(nasal::CallContext c) { return c.requireArg(0); } BOOST_AUTO_TEST_CASE( cppbind_misc_testing ) { - naContext c = naNewContext(); + TestContext c; naRef r; using namespace nasal; - r = to_nasal(c, ENUM_ANOTHER); - BOOST_CHECK_EQUAL(from_nasal(c, r), ENUM_ANOTHER); + r = c.to_nasal(ENUM_ANOTHER); + BOOST_CHECK_EQUAL(c.from_nasal(r), ENUM_ANOTHER); - r = to_nasal(c, "Test"); + r = c.to_nasal("Test"); BOOST_CHECK( strncmp("Test", naStr_data(r), naStr_len(r)) == 0 ); - BOOST_CHECK_EQUAL(from_nasal(c, r), "Test"); + BOOST_CHECK_EQUAL(c.from_nasal(r), "Test"); - r = to_nasal(c, std::string("Test")); + r = c.to_nasal(std::string("Test")); BOOST_CHECK( strncmp("Test", naStr_data(r), naStr_len(r)) == 0 ); - BOOST_CHECK_EQUAL(from_nasal(c, r), "Test"); + BOOST_CHECK_EQUAL(c.from_nasal(r), "Test"); - r = to_nasal(c, 42); + r = c.to_nasal(42); BOOST_CHECK_EQUAL(naNumValue(r).num, 42); - BOOST_CHECK_EQUAL(from_nasal(c, r), 42); + BOOST_CHECK_EQUAL(c.from_nasal(r), 42); - r = to_nasal(c, 4.2f); + r = c.to_nasal(4.2f); BOOST_CHECK_EQUAL(naNumValue(r).num, 4.2f); - BOOST_CHECK_EQUAL(from_nasal(c, r), 4.2f); + BOOST_CHECK_EQUAL(c.from_nasal(r), 4.2f); float test_data[3] = {0, 4, 2}; - r = to_nasal(c, test_data); + r = c.to_nasal(test_data); SGVec2f vec(0,2); - r = to_nasal(c, vec); - BOOST_CHECK_EQUAL(from_nasal(c, r), vec); + r = c.to_nasal(vec); + BOOST_CHECK_EQUAL(c.from_nasal(r), vec); std::vector std_vec; - r = to_nasal(c, std_vec); + r = c.to_nasal(std_vec); - r = to_nasal(c, "string"); - BOOST_CHECK_THROW(from_nasal(c, r), bad_nasal_cast); + r = c.to_nasal("string"); + BOOST_CHECK_THROW(c.from_nasal(r), bad_nasal_cast); Hash hash(c); hash.set("vec", r); @@ -171,10 +173,10 @@ BOOST_AUTO_TEST_CASE( cppbind_misc_testing ) it1 = it2; it3 = it2; - r = to_nasal(c, hash); + r = c.to_nasal(hash); BOOST_REQUIRE( naIsHash(r) ); - simgear::StringMap string_map = from_nasal(c, r); + simgear::StringMap string_map = c.from_nasal(r); BOOST_CHECK_EQUAL(string_map.at("vec"), "string"); BOOST_CHECK_EQUAL(string_map.at("name"), "my-name"); BOOST_CHECK_EQUAL(string_map.at("string"), "blub"); @@ -260,81 +262,81 @@ BOOST_AUTO_TEST_CASE( cppbind_misc_testing ) Ghost::init("SGWeakRefBasedPtr"); SGWeakRefBasedPtr weak_ptr(new SGWeakReferenceBasedClass()); - naRef nasal_ref = to_nasal(c, weak_ptr), - nasal_ptr = to_nasal(c, weak_ptr.get()); + naRef nasal_ref = c.to_nasal(weak_ptr), + nasal_ptr = c.to_nasal(weak_ptr.get()); BOOST_REQUIRE( naIsGhost(nasal_ref) ); BOOST_REQUIRE( naIsGhost(nasal_ptr) ); - SGWeakRefBasedPtr ptr1 = from_nasal(c, nasal_ref), - ptr2 = from_nasal(c, nasal_ptr); + SGWeakRefBasedPtr ptr1 = c.from_nasal(nasal_ref), + ptr2 = c.from_nasal(nasal_ptr); BOOST_CHECK_EQUAL(weak_ptr, ptr1); BOOST_CHECK_EQUAL(weak_ptr, ptr2); BOOST_REQUIRE( Ghost::isInit() ); - nasal::to_nasal(c, DoubleDerived2Ptr()); + c.to_nasal(DoubleDerived2Ptr()); BasePtr d( new Derived ); - naRef derived = to_nasal(c, d); + naRef derived = c.to_nasal(d); BOOST_REQUIRE( naIsGhost(derived) ); BOOST_CHECK_EQUAL( std::string("DerivedPtr"), naGhost_type(derived)->name ); // Get member function from ghost... naRef thisGetter = naNil(); - BOOST_CHECK( naMember_get(c, derived, to_nasal(c, "this"), &thisGetter) ); + BOOST_CHECK( naMember_get(c, derived, c.to_nasal("this"), &thisGetter) ); BOOST_CHECK( naIsFunc(thisGetter) ); // ...and check if it really gets passed the correct instance typedef boost::function MemFunc; - MemFunc fGetThis = from_nasal(c, thisGetter); + MemFunc fGetThis = c.from_nasal(thisGetter); BOOST_REQUIRE( fGetThis ); BOOST_CHECK_EQUAL( fGetThis(derived), (unsigned long)d.get() ); BasePtr d2( new DoubleDerived ); - derived = to_nasal(c, d2); + derived = c.to_nasal(d2); BOOST_CHECK( naIsGhost(derived) ); BOOST_CHECK_EQUAL( std::string("DoubleDerivedPtr"), naGhost_type(derived)->name ); BasePtr d3( new DoubleDerived2 ); - derived = to_nasal(c, d3); + derived = c.to_nasal(d3); BOOST_CHECK( naIsGhost(derived) ); BOOST_CHECK_EQUAL( std::string("DoubleDerived2Ptr"), naGhost_type(derived)->name ); SGRefBasedPtr ref_based( new SGReferenceBasedClass ); - naRef na_ref_based = to_nasal(c, ref_based.get()); + naRef na_ref_based = c.to_nasal(ref_based.get()); BOOST_CHECK( naIsGhost(na_ref_based) ); - BOOST_CHECK_EQUAL( from_nasal(c, na_ref_based), + BOOST_CHECK_EQUAL( c.from_nasal(na_ref_based), ref_based.get() ); - BOOST_CHECK_EQUAL( from_nasal(c, na_ref_based), ref_based ); + BOOST_CHECK_EQUAL( c.from_nasal(na_ref_based), ref_based ); - BOOST_CHECK_EQUAL( from_nasal(c, derived), d3 ); - BOOST_CHECK_NE( from_nasal(c, derived), d2 ); - BOOST_CHECK_EQUAL( from_nasal(c, derived), + BOOST_CHECK_EQUAL( c.from_nasal(derived), d3 ); + BOOST_CHECK_NE( c.from_nasal(derived), d2 ); + BOOST_CHECK_EQUAL( c.from_nasal(derived), boost::dynamic_pointer_cast(d3) ); - BOOST_CHECK_EQUAL( from_nasal(c, derived), + BOOST_CHECK_EQUAL( c.from_nasal(derived), boost::dynamic_pointer_cast(d3) ); - BOOST_CHECK_THROW( from_nasal(c, derived), bad_nasal_cast ); + BOOST_CHECK_THROW( c.from_nasal(derived), bad_nasal_cast ); std::map instances; - BOOST_CHECK( naIsHash(to_nasal(c, instances)) ); + BOOST_CHECK( naIsHash(c.to_nasal(instances)) ); std::map instances_d; - BOOST_CHECK( naIsHash(to_nasal(c, instances_d)) ); + BOOST_CHECK( naIsHash(c.to_nasal(instances_d)) ); std::map int_map; - BOOST_CHECK( naIsHash(to_nasal(c, int_map)) ); + BOOST_CHECK( naIsHash(c.to_nasal(int_map)) ); std::map > int_vector_map; - BOOST_CHECK( naIsHash(to_nasal(c, int_vector_map)) ); + BOOST_CHECK( naIsHash(c.to_nasal(int_vector_map)) ); simgear::StringMap dict = simgear::StringMap("hello", "value") ("key2", "value2"); - naRef na_dict = to_nasal(c, dict); + naRef na_dict = c.to_nasal(dict); BOOST_REQUIRE( naIsHash(na_dict) ); BOOST_CHECK_EQUAL( Hash(na_dict, c).get("key2"), "value2" ); @@ -346,65 +348,44 @@ BOOST_AUTO_TEST_CASE( cppbind_misc_testing ) Hash obj(c); obj.set("parents", parents); - BOOST_CHECK_EQUAL( from_nasal(c, obj.get_naRef()), d3 ); + BOOST_CHECK_EQUAL( c.from_nasal(obj.get_naRef()), d3 ); // Check recursive parents (aka parent-of-parent) std::vector parents2; parents2.push_back(obj.get_naRef()); Hash derived_obj(c); derived_obj.set("parents", parents2); - BOOST_CHECK_EQUAL( from_nasal(c, derived_obj.get_naRef()), d3 ); + BOOST_CHECK_EQUAL( c.from_nasal(derived_obj.get_naRef()), d3 ); std::vector nasal_objects; nasal_objects.push_back( Ghost::makeGhost(c, d) ); nasal_objects.push_back( Ghost::makeGhost(c, d2) ); nasal_objects.push_back( Ghost::makeGhost(c, d3) ); - naRef obj_vec = to_nasal(c, nasal_objects); + naRef obj_vec = c.to_nasal(nasal_objects); - std::vector objects = from_nasal >(c, obj_vec); + std::vector objects = c.from_nasal >(obj_vec); BOOST_CHECK_EQUAL( objects[0], d ); BOOST_CHECK_EQUAL( objects[1], d2 ); BOOST_CHECK_EQUAL( objects[2], d3 ); - { - // Calling fallback setter for unset values - const char* src_code = "me.test = 3;"; - int errLine = -1; - naRef code = naParseCode( c, to_nasal(c, "source.nas"), 0, - (char*)src_code, strlen(src_code), - &errLine ); - ret = naCallMethod(code, derived, 0, 0, naNil()); + // Calling fallback setter for unset values + BOOST_CHECK_EQUAL( c.exec("me.test = 3;", derived), 3 ); - BOOST_REQUIRE( !naGetError(c) ); // TODO real error check (this seems to - // always return 0... - BOOST_CHECK_EQUAL( from_nasal(c, ret), 3 ); - } - { - // Calling generic (fallback) getter - const char* src_code = "var a = me.get_test;"; - int errLine = -1; - naRef code = naParseCode( c, to_nasal(c, "source.nas"), 0, - (char*)src_code, strlen(src_code), - &errLine ); - ret = naCallMethod(code, derived, 0, 0, naNil()); - - BOOST_REQUIRE( !naGetError(c) ); // TODO real error check (this seems to - // always return 0... - BOOST_CHECK_EQUAL( from_nasal(c, ret), "generic-get" ); - } + // Calling generic (fallback) getter + BOOST_CHECK_EQUAL( c.exec("var a = me.get_test;", derived), + "generic-get" ); //---------------------------------------------------------------------------- // Test nasal::CallContext //---------------------------------------------------------------------------- - int int_vec[] = {1,2,3}; std::map map; naRef args[] = { - to_nasal(c, std::string("test-arg")), - to_nasal(c, 4), - to_nasal(c, int_vec), - to_nasal(c, map) + c.to_nasal(std::string("test-arg")), + c.to_nasal(4), + c.to_nasal(int_vec), + c.to_nasal(map) }; CallContext cc(c, naNil(), sizeof(args)/sizeof(args[0]), args); BOOST_CHECK_EQUAL( cc.requireArg(0), "test-arg" ); @@ -419,15 +400,15 @@ BOOST_AUTO_TEST_CASE( cppbind_misc_testing ) BOOST_CHECK( cc.isVector(2) ); BOOST_CHECK( cc.isHash(3) ); - naRef args_vec = nasal::to_nasal(c, args); + naRef args_vec = c.to_nasal(args); BOOST_CHECK( naIsVector(args_vec) ); //---------------------------------------------------------------------------- // Test nasal::String //---------------------------------------------------------------------------- - String string( to_nasal(c, "Test") ); - BOOST_CHECK_EQUAL( from_nasal(c, string.get_naRef()), "Test" ); + String string( c.to_nasal("Test") ); + BOOST_CHECK_EQUAL( c.from_nasal(string.get_naRef()), "Test" ); BOOST_CHECK_EQUAL( string.c_str(), std::string("Test") ); BOOST_CHECK( string.starts_with(string) ); BOOST_CHECK( string.starts_with(String(c, "T")) ); @@ -453,6 +434,16 @@ BOOST_AUTO_TEST_CASE( cppbind_misc_testing ) BOOST_CHECK_EQUAL( string.find_first_not_of(String(c, "Tse"), 2), 3 ); BOOST_CHECK_EQUAL( string.find_first_not_of(String(c, "abc")), 0 ); BOOST_CHECK_EQUAL( string.find_first_not_of(String(c, "abc"), 20), String::npos ); - - naFreeContext(c); +} + +BOOST_AUTO_TEST_CASE( cppbind_context ) +{ + nasal::Context ctx; + naRef vec = ctx.newVector(1, 2, 3.4, "test"); + BOOST_REQUIRE( naIsVector(vec) ); + + BOOST_CHECK_EQUAL(ctx.from_nasal(naVec_get(vec, 0)), 1); + BOOST_CHECK_EQUAL(ctx.from_nasal(naVec_get(vec, 1)), 2); + BOOST_CHECK_EQUAL(ctx.from_nasal(naVec_get(vec, 2)), 3.4); + BOOST_CHECK_EQUAL(ctx.from_nasal(naVec_get(vec, 3)), "test"); } diff --git a/simgear/nasal/cppbind/test/nasal_gc_test.cxx b/simgear/nasal/cppbind/test/nasal_gc_test.cxx index 0d6e2e09..8288e671 100644 --- a/simgear/nasal/cppbind/test/nasal_gc_test.cxx +++ b/simgear/nasal/cppbind/test/nasal_gc_test.cxx @@ -25,7 +25,7 @@ static naGhostType ghost_type = { static naRef createTestGhost(TestContext& c, intptr_t p) { active_instances.insert(p); - return naNewGhost(c.c, &ghost_type, (void*)p); + return naNewGhost(c, &ghost_type, (void*)p); } //------------------------------------------------------------------------------ diff --git a/simgear/nasal/nasal.h b/simgear/nasal/nasal.h index 7be9bb4f..6f3e3bfa 100644 --- a/simgear/nasal/nasal.h +++ b/simgear/nasal/nasal.h @@ -1,3 +1,6 @@ +///@file +/// The Nasal scripting language +/// #ifndef _NASAL_H #define _NASAL_H #ifdef __cplusplus @@ -15,12 +18,14 @@ extern "C" { #define GCC_PURE #endif +/** Nasal context pointer */ typedef struct Context* naContext; -// The function signature for an extension function: +/** Function signature for an extension function */ typedef naRef (*naCFunction)(naContext ctx, naRef me, int argc, naRef* args); -// The function signature for an extension function with userdata passed back: +/** Function signature for an extension function with @p user_data passed back + */ typedef naRef (*naCFunctionU) (naContext ctx, naRef me, int argc, naRef* args, void* user_data); @@ -258,7 +263,7 @@ void naHash_set(naRef hash, naRef key, naRef val); void naHash_cset(naRef hash, char* key, naRef val); void naHash_delete(naRef hash, naRef key); /** - * Store the keys in ::hash into the vector at ::dst + * Store the keys in @p hash into the vector at @p dst * * @see ::naNewVector */ @@ -273,25 +278,25 @@ typedef struct naGhostType { } naGhostType; /** - * Create a ghost for an object without any attributes. If ::t contains pointers - * to get_member or set_member function they will be ignored. + * Create a ghost for an object without any attributes. If @p t contains + * pointers to get_member or set_member function they will be ignored. */ naRef naNewGhost(naContext c, naGhostType* t, void* ghost); /** * Create a ghost for an object. This version uses the get_member and set_member - * function pointers in ::t upon trying to get or set a member respectively from - * Nasal. + * function pointers in @p t upon trying to get or set a member respectively + * from Nasal. */ naRef naNewGhost2(naContext c, naGhostType* t, void* ghost); naGhostType* naGhost_type(naRef ghost); void* naGhost_ptr(naRef ghost); /** - * Attach a nasal object to the given ghost. Binds the lifetime of @a data to - * the lifetime of the @a ghost. + * Attach a nasal object to the given ghost. Binds the lifetime of @p data to + * the lifetime of the @p ghost. */ void naGhost_setData(naRef ghost, naRef data); /** - * Retrieve the object attached to the @a ghost, previously set with + * Retrieve the object attached to the @p ghost, previously set with * naGhost_setData(). */ naRef naGhost_data(naRef ghost);