2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
18 #include "java/lang/Object.h"
19 #include "java/lang/Class.h"
20 #include "java/lang/String.h"
32 Class *String::class$ = NULL;
33 jmethodID *String::_mids = NULL;
35 jclass String::initializeClass()
39 jclass cls = env->findClass("java/lang/String");
41 _mids = new jmethodID[max_mid];
43 env->getMethodID(cls, "<init>",
46 env->getMethodID(cls, "toString",
47 "()Ljava/lang/String;");
49 env->getMethodID(cls, "length",
52 class$ = (Class *) new JObject(cls);
55 return (jclass) class$->this$;
58 String::String() : Object(env->newObject(initializeClass, &_mids, mid__init_)) {
61 int String::length() const
63 return env->callIntMethod(this$, _mids[mid_length]);
69 #include "structmember.h"
70 #include "functions.h"
76 static int t_String_init(t_String *self,
77 PyObject *args, PyObject *kwds);
78 static PyObject *t_String_length(t_String *self);
80 static PyMethodDef t_String__methods_[] = {
81 DECLARE_METHOD(t_String, length, METH_NOARGS),
82 { NULL, NULL, 0, NULL }
85 DECLARE_TYPE(String, t_String, Object, java::lang::String,
86 t_String_init, 0, 0, 0, 0, 0);
88 static int t_String_init(t_String *self,
89 PyObject *args, PyObject *kwds)
93 switch (PyTuple_Size(args)) {
95 INT_CALL(self->object = String());
98 if (!PyArg_ParseTuple(args, "s", &bytes))
100 INT_CALL(self->object = String(env->fromUTF(bytes)));
103 PyErr_SetString(PyExc_ValueError, "invalid args");
110 static PyObject *t_String_length(t_String *self)
114 OBJ_CALL(length = self->object.length());
115 return PyInt_FromLong(length);