Small refactor
This commit is contained in:
@@ -238,37 +238,7 @@ Int LuaBufferChangeID = 0;
|
|||||||
void ReloadStyle();
|
void ReloadStyle();
|
||||||
extern String BaseLuaConfig;
|
extern String BaseLuaConfig;
|
||||||
|
|
||||||
void ReloadLuaConfig() {
|
void UpdateLuaConfig() {
|
||||||
// Init base config, test that it works and initialize the lua stuff
|
|
||||||
if (LuaBufferChangeID == 0) {
|
|
||||||
if (!luaL_dostring(LuaState, BaseLuaConfig.data) == LUA_OK) {
|
|
||||||
const char *error_message = lua_tostring(LuaState, -1);
|
|
||||||
ReportErrorf("Failed to load base lua config! %s", error_message);
|
|
||||||
lua_pop(LuaState, 1);
|
|
||||||
Assert(!"Invalid codepath");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Init user config
|
|
||||||
Scratch scratch;
|
|
||||||
String lua_config_path = Format(scratch, "%.*s/init.lua", FmtString(ConfigDir));
|
|
||||||
|
|
||||||
#if DEBUG_BUILD
|
|
||||||
// WARNING! Delete config to make sure we are running this code more frequently
|
|
||||||
SDL_RemovePath(lua_config_path.data);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Buffer *lua_buffer = BufferOpenFile(lua_config_path);
|
|
||||||
if (lua_buffer->len == 0) {
|
|
||||||
String16 string16 = ToString16(scratch, BaseLuaConfig);
|
|
||||||
IKnowWhatImDoing_ReplaceText(lua_buffer, {}, string16);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if we loaded from file this should force to read
|
|
||||||
lua_buffer->change_id = 2;
|
|
||||||
LuaBufferChangeID = 1;
|
|
||||||
LuaBufferID = lua_buffer->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (LuaBufferID.id == -1) return;
|
if (LuaBufferID.id == -1) return;
|
||||||
|
|
||||||
Buffer *lua_buffer = GetBuffer(LuaBufferID);
|
Buffer *lua_buffer = GetBuffer(LuaBufferID);
|
||||||
@@ -299,6 +269,38 @@ void ReloadLuaConfig() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InitLuaConfig() {
|
||||||
|
// Init base config, test that it works and initialize the lua stuff
|
||||||
|
if (!luaL_dostring(LuaState, BaseLuaConfig.data) == LUA_OK) {
|
||||||
|
const char *error_message = lua_tostring(LuaState, -1);
|
||||||
|
ReportErrorf("Failed to load base lua config! %s", error_message);
|
||||||
|
lua_pop(LuaState, 1);
|
||||||
|
Assert(!"Invalid codepath");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init user config
|
||||||
|
Scratch scratch;
|
||||||
|
String lua_config_path = Format(scratch, "%.*s/init.lua", FmtString(ConfigDir));
|
||||||
|
|
||||||
|
#if DEBUG_BUILD
|
||||||
|
// WARNING! Delete config to make sure we are running this code more frequently
|
||||||
|
SDL_RemovePath(lua_config_path.data);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Buffer *lua_buffer = BufferOpenFile(lua_config_path);
|
||||||
|
if (lua_buffer->len == 0) {
|
||||||
|
String16 string16 = ToString16(scratch, BaseLuaConfig);
|
||||||
|
IKnowWhatImDoing_ReplaceText(lua_buffer, {}, string16);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if we loaded from file this should force to read
|
||||||
|
lua_buffer->change_id = 2;
|
||||||
|
LuaBufferChangeID = 1;
|
||||||
|
LuaBufferID = lua_buffer->id;
|
||||||
|
|
||||||
|
UpdateLuaConfig();
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
String16 EvalString(Allocator allocator, String16 string16) {
|
String16 EvalString(Allocator allocator, String16 string16) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ void Exec(String16 cmd16, String working_dir) {
|
|||||||
Exec(cmd, working_dir);
|
Exec(cmd, working_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Process_OnUpdate() {
|
void UpdateProcesses() {
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
int64_t buffer_size = 4096;
|
int64_t buffer_size = 4096;
|
||||||
char *buffer = AllocArray(scratch, char, buffer_size);
|
char *buffer = AllocArray(scratch, char, buffer_size);
|
||||||
|
|||||||
@@ -165,9 +165,9 @@ void Update(Event event) {
|
|||||||
|
|
||||||
HandleEvent(event);
|
HandleEvent(event);
|
||||||
|
|
||||||
Process_OnUpdate();
|
UpdateProcesses();
|
||||||
ReloadLuaConfig();
|
UpdateLuaConfig();
|
||||||
ReplaceDebugData();
|
UpdateDebugBuffer();
|
||||||
|
|
||||||
For(IterateInReverse(&order)) {
|
For(IterateInReverse(&order)) {
|
||||||
Window *window = &Windows[it];
|
Window *window = &Windows[it];
|
||||||
@@ -301,7 +301,7 @@ int main()
|
|||||||
InitRender();
|
InitRender();
|
||||||
InitLua();
|
InitLua();
|
||||||
ReloadFont();
|
ReloadFont();
|
||||||
ReloadLuaConfig();
|
InitLuaConfig();
|
||||||
InitWindows();
|
InitWindows();
|
||||||
|
|
||||||
while (AppIsRunning) {
|
while (AppIsRunning) {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ String DebugWindowList(Allocator allocator) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReplaceDebugData() {
|
void UpdateDebugBuffer() {
|
||||||
Buffer *buffer = GetBuffer(DebugBufferID);
|
Buffer *buffer = GetBuffer(DebugBufferID);
|
||||||
|
|
||||||
Window *window = GetActiveWindow();
|
Window *window = GetActiveWindow();
|
||||||
|
|||||||
Reference in New Issue
Block a user