1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
void FileManager::SaveFile(const char* fileName, const Options options)
{
std::cout << options.maxFps << std::endl;
std::cout << options.volume << std::endl;
std::cout << options.smoothTextures << std::endl;
lua_State *L = luaL_newstate();
luaL_openlibs(L);
if (luaL_loadfile(L, "Lua/SaveFile.lua") || lua_pcall(L, 0, 0, 0)) //open file
{
std::cout << "error writing to file: " << fileName << std::endl;
lua_close(L);
}
lua_getglobal(L, "saveFile"); //get the function
lua_pushstring(L, fileName); //push the fileName arg
lua_newtable(L); //create the data to be saved
lua_pushboolean(L, options.smoothTextures); //enter the data to be saved
lua_pushnumber(L, options.volume);
lua_pushnumber(L, options.maxFps);
std::cout << lua_tostring(L, -1) << std::endl;
std::cout << lua_tostring(L, -2) << std::endl;
std::cout << lua_tostring(L, -3) << std::endl;
lua_settable(L, -1); //add the data to the table
lua_settable(L, -2);
lua_settable(L, -3);
lua_settop(L, -4); //set the created table to the top of the stack
if (lua_pcall(L, 2, 0, 0) != EXIT_SUCCESS)
std::cout << "error running function: saveFile" << std::endl;
lua_close(L);
}
|