MCPcopy Create free account
hub / github.com/TASEmulators/fceux / LuaStackToBinaryConverter

Function LuaStackToBinaryConverter

src/lua-engine.cpp:888–1048  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

886static std::vector<const void*> s_metacallStack; // prevents infinite recursion if something's __tostring returns another table that contains that something (when cycle is found, print the inner result without using __tostring)
887
888static void LuaStackToBinaryConverter(lua_State* L, int i, std::vector<unsigned char>& output)
889{
890 int type = lua_type(L, i);
891
892 // the first byte of every serialized item says what Lua type it is
893 output.push_back(type & 0xFF);
894
895 switch(type)
896 {
897 default:
898 {
899 char errmsg [1024];
900 sprintf(errmsg, "values of type \"%s\" are not allowed to be returned from registered save functions.\r\n", luaL_typename(L,i));
901 if(info_print)
902 info_print(info_uid, errmsg);
903 else
904 puts(errmsg);
905 }
906 break;
907 case LUA_TNIL:
908 // no information necessary beyond the type
909 break;
910 case LUA_TBOOLEAN:
911 // serialize as 0 or 1
912 output.push_back(lua_toboolean(L,i));
913 break;
914 case LUA_TSTRING:
915 // serialize as a 0-terminated string of characters
916 {
917 const char* str = lua_tostring(L,i);
918 while(*str)
919 output.push_back(*str++);
920 output.push_back('\0');
921 }
922 break;
923 case LUA_TNUMBER:
924 {
925 double num = (double)lua_tonumber(L,i);
926 int32 inum = (int32)lua_tointeger(L,i);
927 if(num != inum)
928 {
929 PushBinaryItem(num, output);
930 }
931 else
932 {
933 if((inum & ~0xFF) == 0)
934 type = LUAEXT_TBYTE;
935 else if((uint16)(inum & 0xFFFF) == inum)
936 type = LUAEXT_TUSHORT;
937 else if((int16)(inum & 0xFFFF) == inum)
938 type = LUAEXT_TSHORT;
939 else
940 type = LUAEXT_TLONG;
941 output.back() = type;
942 switch(type)
943 {
944 case LUAEXT_TLONG:
945 PushBinaryItem<int32>(static_cast<int32>(inum), output);

Callers 2

LuaStackToBinaryFunction · 0.85
SaveRecordPartialMethod · 0.85

Calls 15

lua_typeFunction · 0.85
lua_tobooleanFunction · 0.85
lua_tonumberFunction · 0.85
lua_tointegerFunction · 0.85
PushBinaryItemFunction · 0.85
lua_checkstackFunction · 0.85
lua_topointerFunction · 0.85
lua_objlenFunction · 0.85
lua_gettopFunction · 0.85
lua_rawgetiFunction · 0.85
PushNilsFunction · 0.85
lua_pushintegerFunction · 0.85

Tested by

no test coverage detected