MCPcopy Create free account
hub / github.com/defold/defold / Sys_GetSaveFile

Function Sys_GetSaveFile

engine/script/src/script_sys.cpp:373–397  ·  view source on GitHub ↗

gets the save-file path * The save-file path is operating system specific and is typically located under the user's home directory. * This function will raise a Lua error if unable to get the save file path. * * @note Setting the environment variable `DM_SAVE_HOME` overrides the default application support path. * * @name sys.get_save_file * @param application_id

Source from the content-addressed store, hash-verified

371 * ```
372 */
373 static int Sys_GetSaveFile(lua_State* L)
374 {
375 const char* application_id = luaL_checkstring(L, 1);
376
377 char app_support_path[1024];
378 dmSys::Result r = dmSys::GetApplicationSavePath(application_id, app_support_path, sizeof(app_support_path));
379 if (r != dmSys::RESULT_OK)
380 {
381 return luaL_error(L, "Unable to locate application support path for \"%s\": (%d)", application_id, r);
382 }
383
384 const char* filename = luaL_checkstring(L, 2);
385 char* dm_home = dmSys::GetEnv("DM_SAVE_HOME");
386 // Higher priority
387 if (dm_home)
388 {
389 dmStrlCpy(app_support_path, dm_home, sizeof(app_support_path));
390 }
391
392 dmStrlCat(app_support_path, dmPath::PATH_CHARACTER, sizeof(app_support_path));
393 dmStrlCat(app_support_path, filename, sizeof(app_support_path));
394 lua_pushstring(L, app_support_path);
395
396 return 1;
397 }
398
399
400 /*# gets the application path

Callers

nothing calls this directly

Calls 6

luaL_errorFunction · 0.85
dmStrlCpyFunction · 0.85
dmStrlCatFunction · 0.85
lua_pushstringFunction · 0.85
GetApplicationSavePathFunction · 0.50
GetEnvFunction · 0.50

Tested by

no test coverage detected