MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / lua_serial_readstring

Function lua_serial_readstring

libraries/AP_Scripting/lua_bindings.cpp:832–852  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

830}
831
832int lua_serial_readstring(lua_State *L) {
833 binding_argcheck(L, 2);
834
835 AP_Scripting_SerialAccess * port = check_AP_Scripting_SerialAccess(L, 1);
836
837 // create a buffer sized to hold the number of bytes the user wants to read
838 luaL_Buffer b;
839 const uint16_t req_bytes = get_uint16_t(L, 2);
840 uint8_t *data = (uint8_t *)luaL_buffinitsize(L, &b, req_bytes);
841
842 // read up to that number of bytes
843 const ssize_t read_bytes = port->read(data, req_bytes);
844 if (read_bytes < 0) {
845 return 0; // error, return nil
846 }
847
848 // push the buffer as a string, truncated to the number of bytes actually read
849 luaL_pushresultsize(&b, read_bytes);
850
851 return 1;
852}
853
854/*
855 directory listing, return table of files in a directory

Callers

nothing calls this directly

Calls 3

luaL_buffinitsizeFunction · 0.85
luaL_pushresultsizeFunction · 0.85
readMethod · 0.45

Tested by

no test coverage detected