Conflicts: .project COPYRIGHT Doc/Manual/style.css Examples/Makefile.in Examples/test-suite/common.mk Lib/typemaps/strings.swg Makefile.in Source/DOH/fio.c Source/Makefile.am Source/Modules/emit.cxx Source/Modules/javascript.cxx configure.in git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/oliverb-javascript-v8@13764 626c5289-ae23-0410-ae9c-e8d60b6d4f22
71 lines
1.9 KiB
OpenEdge ABL
Executable file
71 lines
1.9 KiB
OpenEdge ABL
Executable file
/* -----------------------------------------------------------------------------
|
|
* std_string.i
|
|
*
|
|
* Typemaps for std::string and const std::string&
|
|
* These are mapped to a JSCore String and are passed around by value.
|
|
*
|
|
* To use non-const std::string references use the following %apply. Note
|
|
* that they are passed by value.
|
|
* %apply const std::string & {std::string &};
|
|
* ----------------------------------------------------------------------------- */
|
|
|
|
%{
|
|
#include <string>
|
|
%}
|
|
|
|
namespace std {
|
|
|
|
%naturalvar string;
|
|
|
|
class string;
|
|
|
|
// string
|
|
|
|
%typemap(in) string
|
|
%{ if (!$input) {
|
|
// TODO: Throw exception?
|
|
return NULL;
|
|
}
|
|
JSStringRef $1_str = JSValueToStringCopy(context, $input, NULL);
|
|
size_t $1_strsize = JSStringGetMaximumUTF8CStringSize($1_str);
|
|
char* $1_cstr = (char *)malloc($1_strsize * sizeof(char));
|
|
JSStringGetUTF8CString($1_str, $1_cstr, $1_strsize);
|
|
$1 = std::string($1_cstr);
|
|
%}
|
|
|
|
%typemap(out) string %{
|
|
JSStringRef jsstring = JSStringCreateWithUTF8CString($1.c_str());
|
|
$result = JSValueMakeString(context, jsstring);
|
|
JSStringRelease(jsstring);
|
|
%}
|
|
|
|
%typemap(freearg) string //TODO: Not working: A memory leak
|
|
%{ free($1_cstr); %}
|
|
|
|
//%typemap(typecheck) string = char *;
|
|
|
|
// const string &
|
|
%typemap(in) const string &
|
|
%{ if (!$input) {
|
|
// TODO: Throw exception?
|
|
return NULL;
|
|
}
|
|
JSStringRef $1_str = JSValueToStringCopy(context, $input, NULL);
|
|
size_t $1_strsize = JSStringGetMaximumUTF8CStringSize($1_str);
|
|
char* $1_cstr = (char *)malloc($1_strsize * sizeof(char));
|
|
JSStringGetUTF8CString($1_str, $1_cstr, $1_strsize);
|
|
$1 = new std::string($1_cstr);
|
|
%}
|
|
|
|
%typemap(out) const string & %{
|
|
JSStringRef jsstring = JSStringCreateWithUTF8CString($1.c_str());
|
|
$result = JSValueMakeString(context, jsstring);
|
|
JSStringRelease(jsstring);
|
|
%}
|
|
|
|
%typemap(freearg) const string & //TODO: Not working: A memory leak
|
|
%{ free($1_cstr); %}
|
|
|
|
//%typemap(typecheck) const string & = char *;
|
|
|
|
}
|