lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, Jul 28, 2009 at 3:59 PM, John Dunn wrote:
>    luaL_error(L, "value too big");
>    ...
>    lua_pushstring(L,"value too big");
>    lua_error(L);
> ,,,
> When I raise the error inside my NewIndex function, is there a way to
> get the current line number from the script being executed so it acts
> the same as the :SetValue() call?

luaL_error (unlike lua_error) prepends line info [1].  In fact, the
implementation of luaL_error calls luaL_where [2]:

  LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) {
    va_list argp;
    va_start(argp, fmt);
    luaL_where(L, 1);
    lua_pushvfstring(L, fmt, argp);
    va_end(argp);
    lua_concat(L, 2);
    return lua_error(L);
  }

[1] http://www.lua.org/manual/5.1/manual.html#luaL_error
[2] http://www.lua.org/manual/5.1/manual.html#luaL_where