In lua, the # operator is used to obtain the object size. For table, the number of table elements is obtained, and for string, the string length is obtained.
The other way to obtain data is table. getn (obj). However, this method has been marked as abolished. Use the generic and concise # operator whenever possible.
Lua_objlen () is required to use the lua api to implement this function, but this function is not provided in luabind.
First, find the type function of the object type in the object. hpp of luabind source code, and add the following code
1: template <class ValueWrapper>
2: inline int obj_size (ValueWrapper const & value)
3 :{
4: lua_State * interpreter = value_wrapper_traits <ValueWrapper >:: interpreter (
5: value
6 :);
7:
8: value_wrapper_traits <ValueWrapper >:: unwrap (interpreter, value );
9: detail: stack_pop pop (interpreter, 1 );
10: return lua_objlen (interpreter,-1 );
11 :}
Re-compile your code, you can use luabind: obj_size (obj) to get the object size.
From the treasure Building