--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You may want to try this ( modified version of stackoverflow post 21816960 ):
Test.c
#include <emscripten.h>
#include <string.h>
int stringLen(char* p)
{
return strlen(p);
}Use the following command to compile the cpp code :
emcc Test.c -s EXPORTED_FUNCTIONS="['_stringLen']Sample test code :
Test.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Hello World !</title>
<script src="a.out.js"></script>
<script>
var strLenFunction = Module.cwrap('stringLen', 'number', ['string']);
var len1 = strLenFunction("hi."); // alerts 3
alert(len1);
var len2 = strLenFunction("Hello World"); // alerts 11
alert(len2);
</script>
</head>
</html>I managed to add bindings to my library, thanks. However, most of the functions in the library rely on passing char* back-and-forth, so adding wrapper functions to all of them is unfeasible. It would also make the API look different from JS than from C, which is a blocker for me. Do you maybe know when char* support would be added to embind?—
Lóránt
On Tue, Aug 26, 2014 at 10:31 PM, Chad Austin <ch...@imvu.com> wrote:
I believe that's on the embind todo list. (Since pointers don't have unambiguous semantics, the bindings would need explicit pointer policies, and that work hasn't been done yet.)
However, there's a workaround! You can do something like:#include <Library.h>// assume Library.h declares: void libraryFunction(const char*);static void libraryFunctionWrapper(const std::string& s) {libraryFunction(s.c_str());}function("libraryFunction", &libraryFunctionWrapper);
EMSCRIPTEN_BINDINGS(Library) {}
On Tue, Aug 26, 2014 at 1:28 PM, Lóránt Pintér <lorant...@prezi.com> wrote:
Hi,Is it possible in embind to treat char* as a JS string? If not, how can I call a C function with a char* parameter from JS?Thanks—
Lóránt
--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.