Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*++
- Copyright (c) The Binding of Isaac: Ascension Team
- Licensed under the MIT license.
- Module Name:
- - Ascension.h
- Abstract:
- - This file contains the source code to the Ascension Team's lua compiler
- and extra useful data types, methods, and functions.
- Author(s):
- - Shen Lee (xiang)
- --*/
- #ifndef ASCENSION_DOT_H
- #define ASCENSION_DOT_H
- #include <iostream>
- #include <fstream>
- #include <cstring>
- #include <string>
- #include <vector>
- #include <algorithm>
- #define __VOLATILE
- namespace Ascension
- {
- namespace Lua
- {
- typedef struct LuaEngine
- {
- static __VOLATILE char* LE_Translate(const char* __script) noexcept;
- static signed LE_Create(const char* __script, const char* __content) noexcept;
- static signed LE_Execute(const char* __script) noexcept;
- static signed LE_Delete(const char* __script) noexcept;
- private:
- static bool LE_Find(const char* __script) noexcept;
- };
- // Translates native C/C++ code into valid Lua script
- __VOLATILE char* LuaEngine::LE_Translate(const char* __script) noexcept
- {
- // Left empty until further development status is reached
- }
- // Creates a Lua source file, with provided content
- signed LuaEngine::LE_Create(const char* __script, const char* __content) noexcept
- {
- std::ofstream file;
- file.open(__script, std::ios::out);
- while (file.is_open())
- {
- file.write(__content, strlen(__content));
- file.close();
- return 0;
- }
- return -1;
- }
- // Runs the given Lua file, using the system's default interpreter
- signed LuaEngine::LE_Execute(const char* __script) noexcept
- {
- std::string script_str = static_cast<std::string>(__script);
- if (LE_Find(__script))
- {
- system(("lua " + script_str).c_str());
- return 0;
- }
- else
- {
- return -1;
- }
- return -1;
- }
- // Deletes the target Lua file from the disk
- signed LuaEngine::LE_Delete(const char* __script) noexcept
- {
- if (LE_Find(__script))
- {
- return (remove(__script) == 0 ? 0 : -1);
- }
- else
- {
- return -1;
- }
- return -1;
- }
- // Searches the given directory for the file
- bool LuaEngine::LE_Find(const char* __script) noexcept
- {
- std::ofstream file;
- file.open(__script, std::ios_base::in);
- if (file.is_open())
- {
- file.close();
- return true;
- }
- else
- {
- return false;
- }
- return false;
- }
- } // namespace Lua
- } // namespace Ascension
- #endif // ASCENSION_DOT_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement