@@ -45,7 +45,7 @@ cdef extern from "emscripten.h":
4545
4646 int emscripten_get_compiler_setting(const char * name)
4747 void emscripten_debugger()
48- # void emscripten_log(int flags, ...)
48+ void emscripten_log(int flags, ...)
4949 int emscripten_get_callstack(int flags, char * out, int maxbytes)
5050
5151cdef extern from " emscripten/html5.h" :
@@ -557,10 +557,36 @@ def debugger():
557557# open the JavaScript console
558558# emscripten.debugger()
559559
560- # No variadic function support in Cython?
561- # No va_arg variant for emscripten_log either.
562- # def log(flags, *args):
563- # emscripten_log(flags, *args)
560+ def log (flags , *args ):
561+ # No variadic function support in Cython?
562+ # No va_arg variant for emscripten_log either.
563+ # Let's offer limited support
564+ cdef char * format
565+ cdef char * cstr
566+ if len (args) == 0 :
567+ emscripten_log(flags)
568+ elif len (args) > 0 :
569+ format = args[0 ]
570+ if len (args) == 1 :
571+ emscripten_log(flags, format)
572+ elif len (args) == 2 :
573+ arg = args[1 ]
574+ if type (arg) == int :
575+ emscripten_log(flags, format, < int > arg)
576+ elif type (arg) == float :
577+ emscripten_log(flags, format, < float > arg)
578+ elif type (arg) in (str , unicode ):
579+ pystr = arg.encode(' UTF-8' )
580+ cstr = pystr
581+ emscripten_log(flags, format, cstr)
582+ else :
583+ pystr = (" emscripten.log: unsupported argument " + str (type (arg))).encode(' UTF-8' )
584+ cstr = pystr
585+ emscripten_log(flags, cstr)
586+ else :
587+ emscripten_log(flags, " emscripten.log: only up to 2 arguments are supported" )
588+ # import emscripten; emscripten.log(0, "hello %02d", 1)
589+ # import emscripten; emscripten.log(emscripten.LOG_WARN|emscripten.LOG_CONSOLE|emscripten.LOG_C_STACK, "warning!")
564590
565591def get_callstack (flags ):
566592 cdef int size = emscripten_get_callstack(flags, NULL , 0 )
0 commit comments