Skip to content

Commit bc920e3

Browse files
committed
Upgrade to new emscripten_log prototype in 1.39.12
1 parent 6bcdd8a commit bc920e3

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

emscripten.pyx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ cdef extern from "emscripten.h":
5252

5353
int emscripten_get_compiler_setting(const char *name)
5454
void emscripten_debugger()
55-
void emscripten_log(int flags, ...)
55+
void emscripten_log(int flags, const char* format, ...)
5656
int emscripten_get_callstack(int flags, char *out, int maxbytes)
5757

5858
LOG_CONSOLE = EM_LOG_CONSOLE
@@ -259,28 +259,27 @@ def debugger():
259259
# open the JavaScript console
260260
# emscripten.debugger()
261261

262-
def log(flags, *args):
262+
def log(flags, fmt, *args):
263263
# No variadic function support in Cython?
264264
# No va_arg variant for emscripten_log either.
265265
# Let's offer limited support
266-
cdef char* format
267266
cdef char* cstr
267+
cdef char* cformat
268+
pystrfmt = fmt.encode('UTF-8')
269+
cformat = pystrfmt
268270
if len(args) == 0:
269-
emscripten_log(flags)
271+
emscripten_log(flags, cformat)
270272
elif len(args) > 0:
271-
format = args[0]
272273
if len(args) == 1:
273-
emscripten_log(flags, format)
274-
elif len(args) == 2:
275-
arg = args[1]
274+
arg = args[0]
276275
if type(arg) == int:
277-
emscripten_log(flags, format, <int>arg)
276+
emscripten_log(flags, cformat, <int>arg)
278277
elif type(arg) == float:
279-
emscripten_log(flags, format, <float>arg)
278+
emscripten_log(flags, cformat, <float>arg)
280279
elif type(arg) in (str, unicode):
281280
pystr = arg.encode('UTF-8')
282281
cstr = pystr
283-
emscripten_log(flags, format, cstr)
282+
emscripten_log(flags, cformat, cstr)
284283
else:
285284
pystr = ("emscripten.log: unsupported argument " + str(type(arg))).encode('UTF-8')
286285
cstr = pystr
@@ -289,6 +288,9 @@ def log(flags, *args):
289288
emscripten_log(flags, "emscripten.log: only up to 2 arguments are supported")
290289
# import emscripten; emscripten.log(0, "hello %02d", 1)
291290
# 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"é")
292294

293295
def get_callstack(flags):
294296
cdef int size = emscripten_get_callstack(flags, NULL, 0)

0 commit comments

Comments
 (0)