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'
This commit is contained in:
wm4 2014-05-26 23:53:29 +02:00
parent 9acd263542
commit 799b5e1a5d
1 changed files with 3 additions and 1 deletions

View File

@ -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;