marrub
/
LoveToken
Archived
1
0
Fork 0

asdfsdh maybe I should remember to test these before committing them

pull/1/head
Marrub 2015-06-05 13:47:39 -04:00
parent 5cc14adf4f
commit f0e77b0014
1 changed files with 36 additions and 6 deletions

View File

@ -32,6 +32,9 @@ typedef struct
{ {
bool escapeChars; bool escapeChars;
bool stripInvalid; bool stripInvalid;
bool doConvert;
const char *fromCode;
const char *toCode;
} LT_InitInfo; } LT_InitInfo;
typedef struct typedef struct
@ -41,11 +44,16 @@ typedef struct
int pos; int pos;
} LT_Token; } LT_Token;
extern bool LT_AssertError; typedef struct
{
bool failure;
const char *str;
} LT_AssertInfo;
void LT_Init(LT_InitInfo initInfo); void LT_Init(LT_InitInfo initInfo);
void LT_Quit(); void LT_Quit();
bool LT_Assert(bool assertion, const char *str); bool LT_Assert(bool assertion, const char *str);
LT_AssertInfo LT_CheckAssert();
bool LT_OpenFile(const char *filePath); bool LT_OpenFile(const char *filePath);
void LT_CloseFile(); void LT_CloseFile();
@ -56,6 +64,8 @@ char *LT_Escaper(char *str, size_t pos, char escape);
LT_Token LT_GetToken(); LT_Token LT_GetToken();
]]) ]])
local pReturn
function parser:init(initInfo, filePath) function parser:init(initInfo, filePath)
loveToken.LT_Init(initInfo) loveToken.LT_Init(initInfo)
loveToken.LT_OpenFile(filePath) loveToken.LT_OpenFile(filePath)
@ -65,8 +75,20 @@ function parser:assert(assertion, str)
return loveToken.LT_Assert(assertion, str) return loveToken.LT_Assert(assertion, str)
end end
function parser:checkError()
ltAssertion = loveToken.LT_CheckAssert()
if (ltAssertion.str == nil) then
assert(not ltAssertion.failure, "unknown assertion")
else
assert(not ltAssertion.failure, ffi.string(ltAssertion.str))
end
end
function parser:openFile(filePath) function parser:openFile(filePath)
return loveToken.LT_OpenFile(filePath) pReturn = loveToken.LT_OpenFile(filePath)
parser:checkError()
return pReturn
end end
function parser:closeFile() function parser:closeFile()
@ -79,19 +101,27 @@ function parser:quit()
end end
function parser:readNumber() function parser:readNumber()
return ffi.string(loveToken.LT_ReadNumber()) pReturn = loveToken.LT_ReadNumber()
parser:checkError()
return ffi.string(pReturn)
end end
function parser:readString(term) function parser:readString(term)
return ffi.string(loveToken.LT_ReadString(term)) pReturn = loveToken.LT_ReadString(term)
parser:checkError()
return ffi.string(pReturn)
end end
function parser:escaper(str, pos, escape) function parser:escaper(str, pos, escape)
return ffi.string(loveToken.LT_Escaper(str, pos, escape)) pReturn = loveToken.LT_Escaper(str, pos, escape)
parser:checkError()
return ffi.string(pReturn)
end end
function parser:getToken() function parser:getToken()
return loveToken.LT_GetToken() pReturn = loveToken.LT_GetToken()
parser:checkError()
return pReturn
end end
return parser return parser