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 len not null, function sets *len string length.

if value has metatable "__tostring" field, lual_tolstring calls corresponding metamethod value argument, , uses result of call result.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -