[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: luaL_tobuffer
- From: Nodir Temirhodzhaev <nvtem@...>
- Date: Sun, 31 Oct 2004 22:40:21 -0800 (PST)
I suggest to add:
[include/lauxlib.h]
typedef struct luaL_rwBuffer {
char *p;
size_t size;
} luaL_rwBuffer;
LUALIB_API int luaL_tobuffer (lua_State *L, int obj,
luaL_rwBuffer *rwB,
int writeable);
[src/lib/lauxlib.c]
LUALIB_API int luaL_tobuffer (lua_State *L, int obj,
luaL_rwBuffer *rwB,
int writeable) {
obj = abs_index(L, obj);
if (luaL_getmetafield(L, obj, "__tobuffer")) { /*
is there a metafield? */
lua_pushvalue(L, obj);
lua_pushboolean(L, writeable);
lua_call(L, 2, 2);
if (!lua_isnil(L, -2)) {
rwB->p = lua_touserdata(L, -2);
rwB->size = (size_t) lua_tonumber(L, -1);
}
else obj = 0;
lua_pop(L, 2);
}
else if (!writeable && (rwB->p = (char
*)lua_tostring(L, obj)) != NULL)
rwB->size = lua_strlen(L, obj);
else obj = 0;
return obj;
}
__________________________________
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail