]> git.mxchange.org Git - flightgear.git/blobdiff - src/Scripting/NasalString.cxx
Remove debug console output in FGApproachController
[flightgear.git] / src / Scripting / NasalString.cxx
index df29b862b4e77e2c1ac40b5aed2e7f435e062664..fe937a0aa0a96bc680352a381b8dc1785d3e449b 100644 (file)
  *  compare(s)
  *  compare(pos, len, s)
  */
-static naRef f_compare(naContext c, naRef me, int argc, naRef* args)
+static naRef f_compare(const nasal::CallContext& ctx)
 {
-  nasal::CallContext ctx(c, argc, args);
-  nasal::String str = nasal::from_nasal<nasal::String>(c, me),
-                rhs = ctx.requireArg<nasal::String>(argc > 1 ? 2 : 0);
-  size_t pos = argc > 1 ? ctx.requireArg<int>(1) : 0;
-  size_t len = argc > 1 ? ctx.requireArg<int>(2) : 0;
+  nasal::String str = ctx.from_nasal<nasal::String>(ctx.me),
+                rhs = ctx.requireArg<nasal::String>(ctx.argc > 1 ? 2 : 0);
+  size_t pos = ctx.argc > 1 ? ctx.requireArg<int>(1) : 0;
+  size_t len = ctx.argc > 1 ? ctx.requireArg<int>(2) : 0;
 
   if( len == 0 )
     len = nasal::String::npos;
@@ -50,15 +49,25 @@ static naRef f_compare(naContext c, naRef me, int argc, naRef* args)
 /**
  *  Check whether string starts with other string
  */
-static naRef f_starts_with(naContext c, naRef me, int argc, naRef* args)
+static naRef f_starts_with(const nasal::CallContext& ctx)
 {
-  nasal::CallContext ctx(c, argc, args);
-  nasal::String str = nasal::from_nasal<nasal::String>(c, me),
+  nasal::String str = ctx.from_nasal<nasal::String>(ctx.me),
                 rhs = ctx.requireArg<nasal::String>(0);
 
   return naNum( str.starts_with(rhs) );
 }
 
+/**
+ *  Check whether string ends with other string
+ */
+static naRef f_ends_with(const nasal::CallContext& ctx)
+{
+  nasal::String str = ctx.from_nasal<nasal::String>(ctx.me),
+                rhs = ctx.requireArg<nasal::String>(0);
+
+  return naNum( str.ends_with(rhs) );
+}
+
 /**
  *  Helper to convert size_t position/npos to Nasal conventions (-1 == npos)
  */
@@ -75,15 +84,14 @@ naRef pos_to_nasal(size_t pos)
  *
  *  find(c, pos = 0)
  */
-static naRef f_find(naContext c, naRef me, int argc, naRef* args)
+static naRef f_find(const nasal::CallContext& ctx)
 {
-  nasal::CallContext ctx(c, argc, args);
-  nasal::String str = nasal::from_nasal<nasal::String>(c, me),
+  nasal::String str = ctx.from_nasal<nasal::String>(ctx.me),
                 find = ctx.requireArg<nasal::String>(0);
   size_t pos = ctx.getArg<int>(1, 0);
 
   if( find.size() != 1 )
-    naRuntimeError(c, "string::find: single character expected");
+    naRuntimeError(ctx.c, "string::find: single character expected");
 
   return pos_to_nasal( str.find(*find.c_str(), pos) );
 }
@@ -93,10 +101,9 @@ static naRef f_find(naContext c, naRef me, int argc, naRef* args)
  *
  * find_first_of(search, pos = 0)
  */
-static naRef f_find_first_of(naContext c, naRef me, int argc, naRef* args)
+static naRef f_find_first_of(const nasal::CallContext& ctx)
 {
-  nasal::CallContext ctx(c, argc, args);
-  nasal::String str = nasal::from_nasal<nasal::String>(c, me),
+  nasal::String str = ctx.from_nasal<nasal::String>(ctx.me),
                 find = ctx.requireArg<nasal::String>(0);
   size_t pos = ctx.getArg<int>(1, 0);
 
@@ -108,10 +115,9 @@ static naRef f_find_first_of(naContext c, naRef me, int argc, naRef* args)
  *
  * find_first_not_of(search, pos = 0)
  */
-static naRef f_find_first_not_of(naContext c, naRef me, int argc, naRef* args)
+static naRef f_find_first_not_of(const nasal::CallContext& ctx)
 {
-  nasal::CallContext ctx(c, argc, args);
-  nasal::String str = nasal::from_nasal<nasal::String>(c, me),
+  nasal::String str = ctx.from_nasal<nasal::String>(ctx.me),
                 find = ctx.requireArg<nasal::String>(0);
   size_t pos = ctx.getArg<int>(1, 0);
 
@@ -119,12 +125,13 @@ static naRef f_find_first_not_of(naContext c, naRef me, int argc, naRef* args)
 }
 
 //------------------------------------------------------------------------------
-naRef initNasalString(naRef globals, naRef string, naContext c, naRef gcSave)
+naRef initNasalString(naRef globals, naRef string, naContext c)
 {
   nasal::Hash string_module(string, c);
 
   string_module.set("compare", f_compare);
   string_module.set("starts_with", f_starts_with);
+  string_module.set("ends_with", f_ends_with);
   string_module.set("find", f_find);
   string_module.set("find_first_of", f_find_first_of);
   string_module.set("find_first_not_of", f_find_first_not_of);