lua-users home
lua-l archive

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


Hi list,

i am trying to extend the tostring function to do something special
for my own special use tables. I found some example using the syntax
below:

function tostring(a)
   -- do something for special tables ...
   -- otherwise call original function:
   return %tostring(a)
end

But this gives me an error for the % character. Omiting the % results in an
endless loop for obvious reasons ...

How is this done? And perhaps someone even knows how to do this from
a c function? 

lua_pushcfunction(L, my_tostring); 
lua_setfield(L, LUA_GLOBALSINDEX, "tostring");

Overwrites tostring, but how do i call the original function from my "my_tostring"?

I tried "lua_pushstring(L, lua_tostring(L, -1));", but this only works for strings and
numerical values, but not for e.g. tables.

Thanks,
  Till

BTW: The forum is down. Otherwise i would have tried to search there ...