How to pass an array of bytes as an argument to the lua script method from C ++ code? Are only int, float, or string data types allowed? Also how can I get an array of bytes from the lua script method? I will pass an array of source bytes to the script. He will analyze and use it. Thanx.
Depends on what you want to do. Lua strings are immutable byte arrays, so if they are small, it is probably best for you to just turn the byte array into a string with lua_pushlstringand pass it like this: yes, the built-in \ 0 is supported and works fine, But since they are immutable, Lua ultimately in the end, it will copy the line every time you want to change it, so it is not suitable for your requirements.
lua_pushlstring
Other options:
copy the data back and forth between your C ++ byte array and the Lua array (i.e. the number table). It will be quite expensive in memory, but this is probably the easiest way.
wrap the C ++ byte array in lightuserdata and provide Lua bindings so you can access it directly. This is the most efficient, but quite a bit of code.
Int float Lua ( , double).
double
script , C :
lua_pushlightuserdata(L, bufptr);
Lua ( lua_pushlstring):
lua_pushlstring (L, bufptr, buflen);
Lua, .
Lua ( - - , C , Lua - ), userdata get set, ( , ).