%description: basic positive test case for user-defined NED functions (Define_NED_Function() macro) %file: test.ned import testlib.*; network Test { parameters: bool p0 = @TESTNAME@_haveClass("foo%*&@"); bool p1 = @TESTNAME@_haveClass("cMessage"); string p2 = @TESTNAME@_lindex(3, "one", "two", "three", "four"); string p3 = @TESTNAME@_lindex(3, true, 42, "three", false); submodules: dump: Dump; } %file: test.cc #include using namespace omnetpp; namespace @TESTNAME@ { cNedValue nedf_haveClass(cComponent *context, cNedValue argv[], int argc) { return cObjectFactory::find(argv[0].stringValue()) != nullptr; } Define_NED_Function2(nedf_haveClass, "bool @TESTNAME@_haveClass(string className)", "@TESTNAME@", "Returns true if the given C++ class exists" ); cNedValue nedf_lindex(cComponent *context, cNedValue argv[], int argc) { int index = (int)argv[0].doubleValue(); if (index < 0) throw cRuntimeError("lindex(): negative index"); if (index > argc) throw cRuntimeError("lindex(): index out of bounds: %d", index); return argv[index]; } Define_NED_Function2(nedf_lindex, "any @TESTNAME@_lindex(long index, any item1, ...)", "@TESTNAME@", "Returns the indexth item from the arg list item1, item2, etc." ); }; //namespace //%extraargs: --debug-on-errors=true %contains: stdout module Test: Test { parameters: @isNetwork p0 = false p1 = true p2 = "three" p3 = "three" submodules: }