lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I tried it by using:

char *arg1;
arg1 = lua_touserdata(L, 1);
len=lua_objlen(L, 1);

But I get nothing in c. Its just simple binary data from a file read with "rb" from lua.

It should be simple to pass it to c shouldn't it?

On 8/14/2012 11:35 PM, Patrick Rapin wrote:
How do I pass binary data to a c dll from lua?
Well, it depends... The binary data could be represented as a string,
a full userdata, or even a full / light userdata containing a pointer
to your (externally allocated) data.

I retrieve the value in c by using "arg1 = luaL_checklstring(L, 1, &len);",
but than it says "string expected, got userdata".
>From th error message, I guess you are storing your binary data in a
(full?) userdata, but you tried the string function for retrieval. It
won't work.
You should instead use lua_touserdata to retrieve the pointer to the
data, and lua_objlen (5.1) / lua_rawlen (5.2) to get the length in
bytes.