An issue was found in this process using the COCOS2DX Tolua binding. Suppose that one back or input is std::string when we disagree with the inclusion of binary data, and std::string I agree, this leads to incorrect use etc. This can lead to a series of problems, especially when we need to use std::string information.
The solution to the problem is that the code generated by Tolua does not add a length parameter to std::string, which causes the binary data to be truncated once it is encountered.
The change approach is actually very easy, just need to change the Basic.lua script, add such as the following code can be
Index fac0c7a: 4c184c7 100644
---A/projects/lastmile/classes/lua/basic.lua
+ + B/projects/lastmile/classes/lua/basic.lua
@@ -307,7 +307,16 @@ -307,7 "C" {
using namespace cocos2d;
using namespace Cocos2d::extension;
-using namespace Cocosdenshion;])
+using namespace Cocosdenshion;
+
+static std::string bt_tocppstring (lua_state* tolua_s, int narg, const char* def) {
+ if (lua_gettop (tolua_s) <abs (Narg)) {
+ Return "";
+ }
+ size_t length = 0;
+ Const CHAR* data = lua_tolstring (tolua_s, Narg, &length);
+ Return std::string (data, length);
+}]])
replace ([[/* Exported function */
Tolua_api int Tolua_cocos2d_open (lua_state* tolua_s);] [[[]]]
@@ -323,6 +332,10 @@ -323,6 int tolua_cocos2d_open (lua_state* tolua_s);] [[[]]]
Replace ([[Tolua_usertype (tolua_s, "lua_function");]], [[]])
+ Replace ([[[Tolua_tocppstring]], [[bt_tocppstring]])
+
+ Replace ([[Tolua_pushcppstring (tolua_s, (const char*) tolua_ret)], [[Lua_pushlstring (tolua_s, Tolua_ret.c_str (), Tolua_ret.size ());])
+
Replace ([[Toluafix_pushusertype_ccobject (tolua_s, (void*) Tolua_ret]],
[Int nID = (tolua_ret)?
(int) Tolua_ret->m_uid:-1;
int* Pluaid = (tolua_ret)? &tolua_ret->m_nLuaID:NULL;
In fact it will be with the internal cppstring about what changes push and ToString
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
COCOS2DX using Tolua as a problem with string handling