Lua: identify_class

This commit is contained in:
Ilari Liusvaara 2014-01-23 14:45:30 +02:00
parent fa9971c2a0
commit 4caf44e057
3 changed files with 46 additions and 3 deletions

39
lua.lyx
View file

@ -513,7 +513,44 @@ If conversion is successful, returns (true, {converted-string}).
\end_layout
\begin_layout Itemize
If conversion was unsuccessful, returns (
If conversion was unsuccessful, returns (false, {converted-part}, {unconverted-b
ytes}, {error}).
The following errors are defined:
\end_layout
\begin_deeper
\begin_layout Itemize
INVALID: Invalid byte sequence in input
\end_layout
\begin_layout Itemize
INCOMPLETE: The input is cut of in middle of multi-byte sequence
\end_layout
\begin_layout Itemize
INTERNALERR: Internal errror
\end_layout
\end_deeper
\begin_layout Subsection
identify_class: Identify class of object
\end_layout
\begin_layout Itemize
Syntax: string identify_class(userdata object)
\end_layout
\begin_layout Standard
Identifies the class of userdata <object>, if possible.
If no identification is possible, returns
\begin_inset Quotes eld
\end_inset
unknown
\begin_inset Quotes erd
\end_inset
.
\end_layout
\begin_layout Standard

BIN
lua.pdf

Binary file not shown.

View file

@ -67,8 +67,14 @@ namespace
}
}
lua::fnptr lua_tostringx(lua_func_misc, "tostringx", [](lua::state& L, const std::string& fname) ->
int {
lua::fnptr lua_ctype(lua_func_misc, "identify_class", [](lua::state& L, const std::string& fname) -> int {
if(L.type(1) != LUA_TUSERDATA)
return 0;
L.pushlstring(try_recognize_userdata(L, 1));
return 1;
});
lua::fnptr lua_tostringx(lua_func_misc, "tostringx", [](lua::state& L, const std::string& fname) -> int {
std::set<const void*> tmp2;
std::string y = luavalue_to_string(L, 1, tmp2, false);
L.pushlstring(y.c_str(), y.length());