Skip to content

Commit 81d0404

Browse files
committed
js: reimplement mp.log using msg command
1 parent de9b9ef commit 81d0404

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

player/javascript.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include "common/common.h"
3030
#include "options/m_property.h"
3131
#include "common/msg.h"
32-
#include "common/msg_control.h"
3332
#include "common/stats.h"
3433
#include "options/m_option.h"
3534
#include "input/input.h"
@@ -565,21 +564,6 @@ static int checkopt(js_State *J, int idx, const char *def, const char *opts[],
565564
js_error(J, "Invalid %s '%s'", desc, opt);
566565
}
567566

568-
// args: level as string and a variable numbers of args to print. adds final \n
569-
static void script_log(js_State *J)
570-
{
571-
const char *level = js_tostring(J, 1);
572-
int msgl = mp_msg_find_level(level);
573-
if (msgl < 0)
574-
js_error(J, "Invalid log level '%s'", level);
575-
576-
struct mp_log *log = jctx(J)->log;
577-
for (int top = js_gettop(J), i = 2; i < top; i++)
578-
mp_msg(log, msgl, (i == 2 ? "%s" : " %s"), js_tostring(J, i));
579-
mp_msg(log, msgl, "\n");
580-
push_success(J);
581-
}
582-
583567
static void script_find_config_file(js_State *J, void *af)
584568
{
585569
const char *fname = js_tostring(J, 1);
@@ -1155,7 +1139,6 @@ struct fn_entry {
11551139
// Names starting with underscore are wrapped at @defaults.js
11561140
// FN_ENTRY is a normal js C function, AF_ENTRY is an autofree js C function.
11571141
static const struct fn_entry main_fns[] = {
1158-
FN_ENTRY(log, 1),
11591142
AF_ENTRY(wait_event, 1),
11601143
FN_ENTRY(_request_event, 2),
11611144
AF_ENTRY(find_config_file, 1),

player/javascript/defaults.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
// - The names of function expressions are not required, but are used in stack
66
// traces. We name them where useful to show up (fname:#line always shows).
77

8+
mp.log = function(level) {
9+
var cmd = ["msg", level];
10+
for (var i = 1; i < arguments.length; i++)
11+
cmd.push(String(arguments[i]))
12+
mp.command_native(cmd);
13+
}
14+
815
mp.msg = { log: mp.log };
916
mp.msg.verbose = mp.log.bind(null, "v");
1017
var levels = ["fatal", "error", "warn", "info", "debug", "trace"];

0 commit comments

Comments
 (0)