[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: luaL_loadstring error with dumped chunk
- From: Philipp Kraus <philipp.kraus@...>
- Date: Fri, 10 Oct 2014 12:44:38 +0200
Wow, that solves the problem, I have change the load string to loadbuffer -> perfect
Thanks
Phil
Am 10.10.2014 um 10:57 schrieb Victor Bombi <sonoro@telefonica.net>:
> Once I had the same problem.
> Solution was given in the list:
> use luaL_loadbuffer instead of luaL_loadstring
>
> ----- Original Message ----- From: "Philipp Kraus" <philipp.kraus@tu-clausthal.de>
> To: "Lua mailing list" <lua-l@lists.lua.org>
> Sent: Friday, October 10, 2014 9:36 AM
> Subject: Re: luaL_loadstring error with dumped chunk
>
>
>
> Am 10.10.2014 um 08:23 schrieb Sean Conner <sean@conman.org>:
>
>> It was thus said that the Great Philipp Kraus once stated:
>>>
>>> In my main I do something like
>>>
>>> CInterpreter x("function abcd() print(‚test') end“)
>>> CInterpreter y(x.m_binaryscript) <- This line creates the truncated chunk error
>>>
>>> IMHO luaL_loadstring adds the compiled script on the stack top, my Lua
>>> dump function adds the full data into a std::string, because on a
>>> std::string the chunk is ended with \0 (I have tested the call with change
>>> the std::string to std::vector<char> but I get equal errors). The
>>> lua_pcall runs the script, which is on the stack top, so I don’t see my
>>> mistake at the moment why the chunk with should be stored in the
>>> std::string is incomplete.
>>>
>>> Can anybody help me to create a correct dumping process?
>>
>> One question, not knowing C++, but what happens when you call
>> (p_target)->append() with a string with embedded NUL bytes (and not just a
>> NUL character ('\0') at the end)? From your problem, it seems like append()
>> will stop appending when it sees p_size non-NUL characters, or at the first
>> NUL character.
>>
>> -spc (lua_dump() produces binary data … )
>
> Thanks for this hint, I have tested the code with a std::vector<char> also, so on this I add the Lua
> dump data into the vector, but this does not work. I get the same error message.
> My Code with the std::vector<char> shows:
>
> int CInterpreter::dump( lua_State* p_interpreter, const void* p_source, std::size_t p_size, void* p_target )
> {
> std::vector<char>* l_target = static_cast< std::vector<char>* >(p_target);
> const std::size_t l_beginindex = l_target->size();
> try {
> l_target->resize(l_beginindex + p_size);
> memcpy( &((*l_target)[l_beginindex]), p_source, p_size );
>
> } catch (...) {
> return 1;
> }
> return 0;
> }
>
>
> And the Dump-Load-Call is: luaL_loadstring(m_interpreter, &m_binaryscript[0])
> with m_binaryscript = std::vector<char>
>
> IMHO it seems, that I don’t add the correct data into my vector. I have sum the p_size variable
> and the vector or string has got equal number of elements.
>
> Phil
>
>
> -----------------------------------------------------
> Dipl.-Inf. Philipp Kraus
> Clausthal University of Technology
> Department of Informatics
> Julius-Albert-Str. 4, Room 211
> D-38678 Clausthal-Zellerfeld
>
> Phone: +49 - 5323 / 72-7109
> EMail: philipp.kraus@tu-clausthal.de
>
>
>