MCPcopy Create free account
hub / github.com/Tencent/UnLua / ReadBytes

Method ReadBytes

Plugins/UnLua/Source/UnLua/Private/BaseLib/LuaLib_File.cpp:213–250  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

211
212
213 FORCEINLINE void ReadBytes(lua_State* L, int32 TryReadNumber)
214 {
215 if (0 >= TryReadNumber)
216 {
217 //if current is the end of file
218 if (FILE->AtEnd())
219 {
220 lua_pushnil(L);
221 }
222 else
223 {//return an empty lua_string
224 lua_pushliteral(L, "");
225 }
226 }
227 else
228 {
229 //if current is the end of file
230 if (FILE->AtEnd())
231 {
232 lua_pushnil(L);
233 }
234 else
235 {
236 //try read number of bytes (string buffer)
237 TArray<uint8> Buffer;
238 int32 ReadNumber = this->ReadSize(Buffer, TryReadNumber);
239 if (0 >= ReadNumber)
240 {
241 lua_pushnil(L);
242 }
243 else
244 {
245 lua_pushlstring(L, (const char*)Buffer.GetData(), ReadNumber);
246 }
247
248 }
249 }
250 }
251private:
252 bool HelperCheckFileMode(const FString& Mode, uint32& OutFlags, bool& OutIsWrite)
253 {

Callers 1

UE4File_ReadFileFunction · 0.80

Calls 4

ReadSizeMethod · 0.95
lua_pushnilFunction · 0.85
lua_pushlstringFunction · 0.85
GetDataMethod · 0.45

Tested by

no test coverage detected