Browse Source

doc: mention EM_ASM() and dollar warnings.

pull/272/head
Vladimír Vondruš 8 years ago
parent
commit
9118037b3b
  1. 15
      doc/platforms-html5.dox
  2. 7
      doc/snippets/CMakeLists.txt
  3. 41
      doc/snippets/platforms-html5.cpp

15
doc/platforms-html5.dox

@ -554,6 +554,21 @@ the mapping [can be added programmatically](https://docs.python.org/3/library/ht
http.server.SimpleHTTPRequestHandler.extensions_map['.wasm'] = 'application/wasm'
@endcode
@subsection platforms-html5-troubleshooting-emasm Warnings about $ characters when using EM_ASM
The [EM_ASM()](https://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html#interacting-with-code-call-javascript-from-native)
family of macros is using `$0`, `$1`, ... to refer to macro arguments from
JavaScript code. Using them in C++ sources triggers a warning from Clang:
@code{.shell-session}
warning: '$' in identifier
@endcode
Solution is to disable the warning for the offending lines, here for example
when modifying a title element contents through DOM:
@snippet platforms-html5.cpp emasm-dollar
*/
}

7
doc/snippets/CMakeLists.txt

@ -38,12 +38,17 @@ if(CORRADE_TARGET_EMSCRIPTEN AND NOT TARGET_GLES2)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_WEBGL2=1")
endif()
add_library(snippets-Magnum STATIC
set(snippets_Magnum_SRCS
Magnum.cpp
MagnumAnimation.cpp
MagnumAnimation-custom.cpp
MagnumMath.cpp
MagnumMathAlgorithms.cpp)
if(CORRADE_TARGET_EMSCRIPTEN)
list(APPEND snippets_Magnum_SRCS platforms-html5.cpp)
endif()
add_library(snippets-Magnum STATIC ${snippets_Magnum_SRCS})
target_link_libraries(snippets-Magnum PRIVATE Magnum)
set_target_properties(snippets-Magnum PROPERTIES FOLDER "Magnum/doc/snippets")

41
doc/snippets/platforms-html5.cpp

@ -0,0 +1,41 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include <string>
#include <emscripten/emscripten.h>
int main() {
{
/* [emasm-dollar] */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdollar-in-identifier-extension"
std::string title;
EM_ASM_({document.getElementById('title').innerHTML =
Pointer_stringify($0, $1)}, title.data(), title.size());
#pragma GCC diagnostic pop
/* [emasm-dollar] */
}
}
Loading…
Cancel
Save