lua-users home
lua-l archive

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


Jörg has been having problems posting to lua-l.

---------- Forwarded message ---------

Problem 1:

Consider this library code:

////////////////////////////////////////////
#include <lua.h>
#include <lauxlib.h>
#include <stdio.h>
#include <stdlib.h>

int add( lua_State* L )
{
  luaL_argcheck( L, lua_type( L, 1 ) == LUA_TUSERDATA, 1, "" );
  luaL_argcheck( L, lua_type( L, 2 ) == LUA_TUSERDATA, 2, "" );
  return 0;
}

extern int luaopen_xxx( lua_State* L )
{
  void* ud = lua_newuserdata( L, 20 );
  lua_newtable( L );
  lua_pushcfunction( L, add );
  lua_setfield( L, -2, "__add" );
  lua_setmetatable( L, -2 );

  luaL_loadstring( L, "return '' + ..." );
  lua_pushvalue( L, -2 );
  lua_pcall( L, 1, 0, 0 );
  printf( "''+ud: %s\n", lua_tostring( L, -1 ) );
  lua_pop( L, 1 );

  luaL_loadstring( L, "return ... + ''" );
  lua_pushvalue( L, -2 );
  lua_pcall( L, 1, 0, 0 );
  printf( "ud+'': %s\n", lua_tostring( L, -1 ) );
  lua_pop( L, 1 );

  luaL_loadstring( L, "return 42+..." );
  lua_pushvalue( L, -2 );
  lua_pcall( L, 1, 0, 0 );
  printf( "42+ud: %s\n", lua_tostring( L, -1 ) );
  lua_pop( L, 1 );

  exit( 1 );
}
////////////////////////////////////////////

Running it with "lua -lxxx" outputs this:

''+ud: bad argument #1 to '?' ()
ud+'': [string "return ... + ''"]:1: bad argument #2 to 'add' ()
42+ud: [string "return 42+..."]:1: bad argument #1 to 'add' ()

Adding a string with a userdata has no information about the failing function.
But adding a userdata with a string has a good error message.
Same with number + userdata.

Different meta-methods like __sub, __mul, ... have the same problem.


Problem 2:

Loading modules on threads has now a very limited require-depth.
Requiring t1.lua which itself requires t2.lua and so on stops
after 5 levels with "C stack overflow". The number of C-frames when
the error happens is in my case 53 and so quite low.

In Lua 5.3 the limit was much higher (>100)

Best regards,
- Jörg