Your code looks like it will correctly create the element but you cannot
return a JS object to native code like that.

You can only return basic types like numbers unless you use some kind of
higher level binding system such as embind.

See
https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html
for more information on connecting the JS and C++ worlds.

On Fri, May 12, 2023 at 4:22 PM Nicholas Ingrassellino <nickwe...@gmail.com>
wrote:

>
> Sorry, I do not see an edit button but I made a mistake. Here is the
> correction:
> It spits out emscgT �� which I thought was a good sign. Turns out trying
> to create two different elements at two different times always says that
> when cast to either void* or char* (all over types just give me 0).
> On Friday, May 12, 2023 at 6:53:40 PM UTC-4 Nicholas Ingrassellino wrote:
>
>> Good morning all! Or good afternoon or have a great night. You know,
>> wherever you are.
>>
>> I have the following code:
>> void* createElement( const char* type ) {
>>     return EM_ASM_PTR( {
>>         return document.createElement( UTF8ToString( $0 ) );
>>     }, type );
>> };
>>
>> I am calling it like this:
>> std::cout << static_cast< char* >( cppquery::html::createElement( "div" )
>> ) << std::endl;
>>
>> It spits out emscgT �� which I thought was a good sign. Turns out trying
>> to create two different elements at two different times always says that
>> when cast to anything other than either void* or char*.
>>
>> What I am trying to do is crate an element (not yet added to the DOM),
>> store whatever (a pointer, I guess) to it, and use it later with other
>> C++-stored JavaScript element objects.
>>
>> I could just do all the work on the JavaScript side and JSON.stringyify
>> everything but that sounds like way too much.
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/emscripten-discuss/caeb2610-9aaa-4c30-8d4a-4feaad7a0f0en%40googlegroups.com
> <https://groups.google.com/d/msgid/emscripten-discuss/caeb2610-9aaa-4c30-8d4a-4feaad7a0f0en%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/CAL_va2-3TLoJZXSnmpg6TZmk17H5tg%3DKaUHufGxwksMEDQ12wQ%40mail.gmail.com.

Reply via email to