lua-users home
lua-l archive

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


It was thus said that the Great 孙世龙 sunshilong once stated:
> >What's wrong with error()?
> Sorry for my poor English.

  And you missed the point of my first message.  What's the variable name in
the following call?

	self_def_func(150,"test")

There are no variables being passed in.  They are literal values.  Or this
example:

	self_def_func((150 - 32) / 1.8,"test")

Again no variable, but an expression.

  The information you want doesn't exist.  You are assuming a particular way
of passing in a paramter to a function that isn't always the case.  Again,
what's wrong with error()?

int self_def_func(lua_State *L)
{
  int argc = lua_gettop(L);
  int type = lua_type(L,1);
  
  if (type != LUA_TNUMBER)
  {
    luaL_traceback(L,L,"paramter 'temperature' not number",0);
    lua_error(L);
  }
  else
  {
    double val = lua_tonumber(L,1);
    if (var > 100)
    {
      luaL_traceback(L,L,"paramter 'temperature' out of range",0);
      lua_error(L);
    }
  }
}

  You get a stack traceback to the calling location where the problem most
likely is.  

  Again, I repeat, the information you want does not, and probably cannot
exist.

  -spc