Helper function to convert a savestate object to the filename it represents.
| 2939 | |
| 2940 | // Helper function to convert a savestate object to the filename it represents. |
| 2941 | static const char *savestateobj2filename(lua_State *L, int offset) { |
| 2942 | |
| 2943 | // First we get the metatable of the indicated object |
| 2944 | int result = lua_getmetatable(L, offset); |
| 2945 | |
| 2946 | if (!result) |
| 2947 | luaL_error(L, "object not a savestate object"); |
| 2948 | |
| 2949 | // Also check that the type entry is set |
| 2950 | lua_getfield(L, -1, "__metatable"); |
| 2951 | if (strcmp(lua_tostring(L,-1), "FCEU Savestate") != 0) |
| 2952 | luaL_error(L, "object not a savestate object"); |
| 2953 | lua_pop(L,1); |
| 2954 | |
| 2955 | // Now, get the field we want |
| 2956 | lua_getfield(L, -1, "filename"); |
| 2957 | |
| 2958 | // Return it |
| 2959 | return lua_tostring(L, -1); |
| 2960 | } |
| 2961 | |
| 2962 | // Helper function for garbage collection. |
| 2963 | static int savestate_gc(lua_State *L) { |
no test coverage detected