-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add resource files, and add tableinterface class
- Loading branch information
Showing
8 changed files
with
238 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
id ICON "icon.ico" | ||
1 VERSIONINFO | ||
FILEVERSION 1,0,0,0 | ||
PRODUCTVERSION 1,0,0,0 | ||
BEGIN | ||
BLOCK "StringFileInfo" | ||
BEGIN | ||
BLOCK "040904E4" | ||
BEGIN | ||
VALUE "CompanyName", "TMPIM" | ||
VALUE "FileDescription", "A Fantasy Console intended as a tool for pixel art game development." | ||
VALUE "FileVersion", "1.0" | ||
VALUE "InternalName", "riko4" | ||
VALUE "LegalCopyright", "Bryan Becar" | ||
VALUE "OriginalFilename", "riko4.exe" | ||
VALUE "ProductName", "Riko4" | ||
VALUE "ProductVersion", "0.0.1" | ||
END | ||
END | ||
BLOCK "VarFileInfo" | ||
BEGIN | ||
VALUE "Translation", 0x409, 1252 | ||
END | ||
END |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef RIKO4_LUAERROR_H | ||
#define RIKO4_LUAERROR_H | ||
|
||
|
||
#include <string> | ||
#include <utility> | ||
#include <stdexcept> | ||
|
||
class LuaError : public std::runtime_error { | ||
public: | ||
enum class Type { GENERIC, NIL_ARG, BAD_TYPE }; | ||
|
||
private: | ||
Type errorType = Type::GENERIC; | ||
|
||
public: | ||
explicit LuaError(const std::string &error) : runtime_error(error) {} | ||
LuaError(const std::string &error, Type errorType) : runtime_error(error), errorType(errorType) {} | ||
|
||
Type getErrorType() const { | ||
return errorType; | ||
} | ||
}; | ||
|
||
#endif //RIKO4_LUAERROR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include <utility> | ||
|
||
#include "TableInterface.h" | ||
|
||
TableInterface::TableInterface(lua_State *state, int arg) : state(state), arg(arg), offset(lua_gettop(state)) { | ||
if (offset < arg) { | ||
throw LuaError("expected table as argument " + std::to_string(arg) + ", got nil"); | ||
} | ||
|
||
int type = lua_type(state, -offset + arg - 1); | ||
if (type != LUA_TTABLE) { | ||
throw LuaError("expected table as argument " + std::to_string(arg) + ", got " + lua_typename(state, type), | ||
LuaError::Type::NIL_ARG); | ||
} | ||
} | ||
|
||
void TableInterface::throwError(std::string desc) { | ||
if (desc.empty()) { | ||
throw LuaError("bad element '" + lastKey + "' of argument " + std::to_string(arg)); | ||
} else { | ||
throw LuaError("bad element '" + lastKey + "' of argument " + std::to_string(arg) + " (" + desc + ")"); | ||
} | ||
} | ||
|
||
void TableInterface::popToStack(std::string key) { | ||
lua_pushstring(state, key.c_str()); | ||
lua_gettable(state, -(++offset)); | ||
lastKey = key; | ||
} | ||
|
||
double TableInterface::getNumber(std::string key) { | ||
popToStack(key); | ||
|
||
double value; | ||
if (lua_isnil(state, -1)) { | ||
throw LuaError("expected number for element '" + key + "' of argument " + std::to_string(arg) + ", got nil", | ||
LuaError::Type::NIL_ARG); | ||
} else { | ||
int type = lua_type(state, -1); | ||
|
||
if (type == LUA_TNUMBER) { | ||
value = lua_tonumber(state, -1); | ||
} else { | ||
throw LuaError("expected number for element '" + key + "' of argument " + std::to_string(arg) + ", got " + | ||
lua_typename(state, type), LuaError::Type::BAD_TYPE); | ||
} | ||
} | ||
|
||
return value; | ||
} | ||
|
||
double TableInterface::getNumber(std::string key, double defaultValue) { | ||
try { | ||
return getNumber(std::move(key)); | ||
} catch (const LuaError &e) { | ||
if (e.getErrorType() == LuaError::Type::NIL_ARG) | ||
return defaultValue; | ||
else | ||
throw e; | ||
} | ||
} | ||
|
||
int TableInterface::getInteger(std::string key) { | ||
popToStack(key); | ||
|
||
int value; | ||
if (lua_isnil(state, -1)) { | ||
throw LuaError("expected number for element '" + key + "' of argument " + std::to_string(arg) + ", got nil", | ||
LuaError::Type::NIL_ARG); | ||
} else { | ||
int type = lua_type(state, -1); | ||
|
||
if (type == LUA_TNUMBER) { | ||
value = static_cast<int>(lua_tointeger(state, -1)); | ||
} else { | ||
throw LuaError("expected number for element '" + key + "' of argument " + std::to_string(arg) + ", got " + | ||
lua_typename(state, type), LuaError::Type::BAD_TYPE); | ||
} | ||
} | ||
|
||
return value; | ||
} | ||
|
||
int TableInterface::getInteger(std::string key, int defaultValue) { | ||
try { | ||
return getInteger(std::move(key)); | ||
} catch (const LuaError &e) { | ||
if (e.getErrorType() == LuaError::Type::NIL_ARG) | ||
return defaultValue; | ||
else | ||
throw e; | ||
} | ||
} |
Oops, something went wrong.