From 799b5e1a5df15d8004ff8030dd8f4e8b2a25e198 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 26 May 2014 23:53:29 +0200 Subject: lua: slightly nicer diagnostics output When Lua itself prints errors such as: Error: [string "mp.defaults"]:387: syntax error near 'function' It's unclear why the location is prefixed with "string ". And for some reason, it disappears if you prefix the name with '@'. I suppose this is done for the sake of luaL_loadstring. With the '@' prefix added, the output is now: Error: mp.defaults:387: syntax error near 'function' --- player/lua.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'player/lua.c') diff --git a/player/lua.c b/player/lua.c index a37f651857..689be1896b 100644 --- a/player/lua.c +++ b/player/lua.c @@ -162,10 +162,12 @@ static int load_file(struct script_ctx *ctx, const char *fname) static int load_builtin(lua_State *L) { const char *name = luaL_checkstring(L, 1); + char dispname[80]; + snprintf(dispname, sizeof(dispname), "@%s", name); for (int n = 0; builtin_lua_scripts[n][0]; n++) { if (strcmp(name, builtin_lua_scripts[n][0]) == 0) { const char *script = builtin_lua_scripts[n][1]; - if (luaL_loadbuffer(L, script, strlen(script), name)) + if (luaL_loadbuffer(L, script, strlen(script), dispname)) lua_error(L); lua_call(L, 0, 1); return 1; -- cgit v1.2.3