i want export binary chunk lua_dump or luau_dump..
the error: return <-luar
don't have compile error or static problems code, <-luar return
what can do? result problem?
private: const char* buildlua(qstring luascript) { const proto* f; char *bytecode = 0l; size_t bytecodelen = 0; wdata wd = { &bytecodelen, &bytecode }; string ts = luascript.tostdstring(); const char* cs; lua_state *l = lual_newstate(); f=combine(l,0); lual_loadstring(l,ts.c_str()); lual_openlibs(l); lua_lock(l); luau_dump(l,f,kpt_lua_writer,&wd,1); lua_unlock(l); lua_close(l); cs = bytecode; return cs; } static const char* kpt_lua_reader(lua_state *l, void *ud, size_t *size) { unused(l); if ((*(int*)ud)--) { *size=sizeof(function)-1; return function; } else { *size=0; return null; } } static int kpt_lua_writer(lua_state * /*l*/, const void *p, size_t sz, void *ud) { wdata *wd = (wdata *)ud; char *newdata; if((newdata = (char *)realloc(*(wd->data), (*(wd->len)) + sz))) { memcpy(newdata + (*(wd->len)), p, sz); *(wd->data) = newdata; *(wd->len) += sz; } else { free(newdata); return 1; } return 0; } static const proto* combine(lua_state* l, int n) { if (n==1) return toproto(l,-1); else { proto* f; int i=n; if (lua_load(l,kpt_lua_reader,&i,"=(keppedev)",null)!=lua_ok) fatal(lua_tostring(l,-1)); f=toproto(l,-1); (i=0; i<n; i++) { f->p[i]=toproto(l,i-n-1); if (f->p[i]->sizeupvalues>0) f->p[i]->upvalues[0].instack=0; } f->sizelineinfo=0; return f; } } static void fatal(const char* message) { qwidget *widget = new qwidget(); qmessagebox::warning(widget,"keppe develop",message); }
there no need use internals of lua. in case, should call lual_loadstring
or lual_loadbuffer
, not lual_dostring
, executes code in string:
lua_state *l = lual_newstate(); lual_loadstring(l,s.c_str()); lua_dump(l,writer,null); lua_close(l);
however, should test return values of both lual_loadstring
, lua_dump
.
Comments
Post a Comment