File: native_directive.i

package info (click to toggle)
swig 4.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 45,980 kB
  • sloc: cpp: 54,284; ansic: 29,022; java: 17,595; python: 12,734; cs: 10,421; ruby: 7,263; yacc: 6,501; makefile: 5,860; javascript: 5,538; sh: 5,422; perl: 4,246; php: 3,733; ml: 2,198; tcl: 2,015; lisp: 1,448; xml: 115
file content (135 lines) | stat: -rw-r--r-- 3,845 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
%module native_directive

%{
#include <ctype.h>
int alpha_count(const char *instring) {
  int count = 0;
  const char *s = instring;
  while (s && *s) {
    if (isalpha((int)*s))
      count++;
    s++;
  };
  return count;
}
%}

%inline %{
int CountAlphas(const char *instring) {
  return alpha_count(instring);
}
%}

// Languages that support %native should code up language specific implementations below

#if defined(SWIGJAVA)
%native(CountAlphaCharacters) int alpha_count(const char *inputString);
%{
extern "C" JNIEXPORT jint JNICALL Java_native_1directive_native_1directiveJNI_CountAlphaCharacters(JNIEnv *jenv, jclass jcls, jstring instring) {
  jint jresult = 0 ;
  (void)jcls;

  if (instring) {
    const char *s = (char *)jenv->GetStringUTFChars(instring, 0);
    if (s) {
      jresult = (jint)alpha_count(s);
      jenv->ReleaseStringUTFChars(instring, s);
    }
  }
  return jresult;
}
%}
#endif


// TODO: C#
// TODO: Python


#ifdef SWIGJAVASCRIPT
%native(CountAlphaCharacters) void JavaScript_alpha_count();
#if defined(SWIG_JAVASCRIPT_NAPI)      /* engine = napi */
%{

static Napi::Value JavaScript_alpha_count(const Napi::CallbackInfo &info) {
  Napi::Env env = info.Env();
  Napi::EscapableHandleScope scope(env);

  Napi::Value jsresult;
  char *arg1 = (char *)0;
  int res1;
  char *buf1 = 0;
  int alloc1 = 0;
  int result;
  if (info.Length() != 1) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for _wrap_alpha_count.");
  res1 = SWIG_AsCharPtrAndSize(info[0], &buf1, NULL, &alloc1);
  if (!SWIG_IsOK(res1))
    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "alpha_count" "', argument " "1"" of type '" "char const *""'");
  arg1 = reinterpret_cast< char * >(buf1);
  result = (int)alpha_count((char const *)arg1);
  jsresult = SWIG_From_int(env, static_cast< int >(result));
  if (alloc1 == SWIG_NEWOBJ) delete[] buf1;
  return scope.Escape(jsresult);
fail:
  return Napi::Value();
}

%}
#elif defined(SWIG_JAVASCRIPT_V8) /* engine = node || v8 */
%{

static SwigV8ReturnValue JavaScript_alpha_count(const SwigV8Arguments &args) {
  SWIGV8_HANDLESCOPE();
  SWIGV8_VALUE jsresult;
  char *arg1 = (char *)0;
  int res1;
  char *buf1 = 0;
  int alloc1 = 0;
  int result;
  if(args.Length() != 1) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for _wrap_alpha_count.");
  res1 = SWIG_AsCharPtrAndSize(args[0], &buf1, NULL, &alloc1);
  if (!SWIG_IsOK(res1))
    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "alpha_count" "', argument " "1"" of type '" "char const *""'");
  arg1 = reinterpret_cast< char * >(buf1);
  result = (int)alpha_count((char const *)arg1);
  jsresult = SWIG_From_int(static_cast< int >(result));
  if (alloc1 == SWIG_NEWOBJ) delete[] buf1;
  SWIGV8_RETURN(jsresult);
fail:
  SWIGV8_RETURN(SWIGV8_UNDEFINED());
}

%}
#elif defined(SWIG_JAVASCRIPT_JSC) /* engine = jsc */
%{

static JSValueRef JavaScript_alpha_count(JSContextRef context, JSObjectRef function,
  JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
{
  char *arg1 = (char *)0;
  int res1;
  char *buf1 = 0;
  int alloc1 = 0;
  int result;
  JSValueRef jsresult;
  if (argc != 1) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments.");
  res1 = SWIG_JSC_AsCharPtrAndSize(context, argv[0], &buf1, NULL, &alloc1);
  if (!SWIG_IsOK(res1))
    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "alpha_count" "', argument " "1"" of type '" "char const *""'");
  arg1 = reinterpret_cast< char * >(buf1);
  result = (int)alpha_count((char const *)arg1);
  jsresult = SWIG_From_int  SWIG_JSC_FROM_CALL_ARGS(static_cast< int >(result));
  if (alloc1 == SWIG_NEWOBJ) delete[] buf1;
  return jsresult;
fail:
  return JSValueMakeUndefined(context);
}

%}
#else
%{
#error No valid JS engine configured
%}
#endif /* engine */
#endif /* SWIGJAVASCRIPT */