@@ -52,7 +52,7 @@ cdef extern from "emscripten.h":
52
52
53
53
int emscripten_get_compiler_setting(const char * name)
54
54
void emscripten_debugger()
55
- void emscripten_log(int flags, ...)
55
+ void emscripten_log(int flags, const char * format, ...)
56
56
int emscripten_get_callstack(int flags, char * out, int maxbytes)
57
57
58
58
LOG_CONSOLE = EM_LOG_CONSOLE
@@ -259,28 +259,27 @@ def debugger():
259
259
# open the JavaScript console
260
260
# emscripten.debugger()
261
261
262
- def log (flags , *args ):
262
+ def log (flags , fmt , *args ):
263
263
# No variadic function support in Cython?
264
264
# No va_arg variant for emscripten_log either.
265
265
# Let's offer limited support
266
- cdef char * format
267
266
cdef char * cstr
267
+ cdef char * cformat
268
+ pystrfmt = fmt.encode(' UTF-8' )
269
+ cformat = pystrfmt
268
270
if len (args) == 0 :
269
- emscripten_log(flags)
271
+ emscripten_log(flags, cformat )
270
272
elif len (args) > 0 :
271
- format = args[0 ]
272
273
if len (args) == 1 :
273
- emscripten_log(flags, format)
274
- elif len (args) == 2 :
275
- arg = args[1 ]
274
+ arg = args[0 ]
276
275
if type (arg) == int :
277
- emscripten_log(flags, format , < int > arg)
276
+ emscripten_log(flags, cformat , < int > arg)
278
277
elif type (arg) == float :
279
- emscripten_log(flags, format , < float > arg)
278
+ emscripten_log(flags, cformat , < float > arg)
280
279
elif type (arg) in (str , unicode ):
281
280
pystr = arg.encode(' UTF-8' )
282
281
cstr = pystr
283
- emscripten_log(flags, format , cstr)
282
+ emscripten_log(flags, cformat , cstr)
284
283
else :
285
284
pystr = (" emscripten.log: unsupported argument " + str (type (arg))).encode(' UTF-8' )
286
285
cstr = pystr
@@ -289,6 +288,9 @@ def log(flags, *args):
289
288
emscripten_log(flags, " emscripten.log: only up to 2 arguments are supported" )
290
289
# import emscripten; emscripten.log(0, "hello %02d", 1)
291
290
# import emscripten; emscripten.log(emscripten.LOG_WARN|emscripten.LOG_CONSOLE|emscripten.LOG_C_STACK, "warning!")
291
+ # emscripten_log doesn't to properly support UTF-8
292
+ # import emscripten; emscripten.log(0, u"é")
293
+ # import emscripten; emscripten.log(0, "%s", u"é")
292
294
293
295
def get_callstack (flags ):
294
296
cdef int size = emscripten_get_callstack(flags, NULL , 0 )
0 commit comments