added command '-code-watch <code.lua>' to not only inject code from file, but also reload it on window gained focus sdl event

This commit is contained in:
Matheus Lessa 2017-10-16 16:22:25 -02:00
parent 0e38df48e3
commit 73c6a00346
1 changed files with 9 additions and 5 deletions

View File

@ -2282,10 +2282,10 @@ static bool loadFileIntoBuffer(Console* console, char* buffer, const char* fileN
s32 size = 0;
void* contents = fsReadFile(fileName, &size);
memset(buffer, 0, TIC_CODE_SIZE);
if(contents)
{
memset(buffer, 0, TIC_CODE_SIZE);
if(size > TIC_CODE_SIZE)
{
char messageBuffer[256];
@ -2317,7 +2317,8 @@ static void tryReloadCode(Console* console, char* codeBuffer)
static void cmdInjectCode(Console* console, const char* param, const char* name)
{
if(strcmp(param, "-code") == 0)
bool watch = strcmp(param, "-code-watch") == 0;
if(strcmp(param, "-code") == 0 || watch)
{
bool loaded = loadFileIntoBuffer(console, &embed.file.code.data, name);
@ -2326,8 +2327,11 @@ static void cmdInjectCode(Console* console, const char* param, const char* name)
embed.yes = true;
embed.fast = true;
console->codeLiveReload.active = true;
strcpy(console->codeLiveReload.fileName, name);
if(watch)
{
console->codeLiveReload.active = true;
strcpy(console->codeLiveReload.fileName, name);
}
}
}
}