Lua's tostring() in C? -
is there lua api function equivalent tostring(), or have following in c code?
lua_getglobal(l, "tostring"); // ... push value convert, and: lua_call(l, 1, 1); the long story:
i'm writing alert(message) function in c (callable lua) show message user. if message isn't string (e.g., boolean or nil), want convert sane. there's lua function this, tostring(), wondering if lua's c api provides "direct" way this.
use lual_tolstring
from reference:
[-0, +1, e]
const char *lual_tolstring (lua_state *l, int idx, size_t *len);converts lua value @ given index c string in reasonable format. resulting string pushed onto stack , returned function. if
lennotnull, function sets*lenstring length.if value has metatable "
__tostring" field,lual_tolstringcalls corresponding metamethod value argument, , uses result of call result.
Comments
Post a Comment