@@ -102,15 +102,51 @@ blobsProfiler.RegisterSubModule("Lua", "Globals", {
102
102
RefreshButton = " Re-scan" -- TODO: I couldn't get this to play nice, so I gave up for now
103
103
})
104
104
105
+ local function luaExecuteFilesInit ()
106
+ if not file .Exists (" blobsProfiler" , " DATA" ) then
107
+ file .CreateDir (" blobsProfiler" )
108
+ end
109
+
110
+ if not file .Exists (" blobsProfiler/Client_LuaExecute.txt" , " DATA" ) then
111
+ file .Write (" blobsProfiler/Client_LuaExecute.txt" , [[ print("Hello client!")]] )
112
+ end
113
+
114
+ if not file .Exists (" blobsProfiler/Server_LuaExecute.txt" , " DATA" ) then
115
+ file .Write (" blobsProfiler/Server_LuaExecute.txt" , [[ print("Hello server!")]] )
116
+ end
117
+ end
118
+
119
+ if CLIENT then
120
+ luaExecuteFilesInit ()
121
+ end
122
+
105
123
blobsProfiler .RegisterSubModule (" Lua" , " Execute" , {
106
124
Icon = " icon16/script_code.png" ,
107
125
OrderPriority = 2 ,
108
126
CustomPanel = function (luaState , parentPanel )
109
- local dhtmlPanel = blobsProfiler .generateAceEditorPanel (parentPanel )
127
+ luaExecuteFilesInit ()
128
+
129
+ local preLoadContent = file .Read (" blobsProfiler/" .. luaState .. " _LuaExecute.txt" )
130
+ local dhtmlPanel = blobsProfiler .generateAceEditorPanel (parentPanel , preLoadContent or [[ print("Hello world!")]] )
110
131
111
132
dhtmlPanel :Dock (FILL )
133
+ dhtmlPanel .lastCode = preLoadContent
134
+
135
+ dhtmlPanel :AddFunction (" gmod" , " saveContentsToFile" , function (value )
136
+ if value ~= dhtmlPanel .lastCode then -- prevent unnecessary writes
137
+ blobsProfiler .Log (blobsProfiler .L_DEBUG , " Writing Lua Execute editor content to: 'blobsProfiler/" .. luaState .. " _LuaExecute.txt'" )
138
+ file .Write (" blobsProfiler/" .. luaState .. " _LuaExecute.txt" , value )
139
+ dhtmlPanel .lastCode = value
140
+ end
141
+ end )
112
142
113
143
dhtmlPanel :AddFunction (" gmod" , " receiveEditorContent" , function (value )
144
+ if value ~= dhtmlPanel .lastCode then -- prevent unnecessary writes
145
+ blobsProfiler .Log (blobsProfiler .L_DEBUG , " Writing Lua Execute editor content to: 'blobsProfiler/" .. luaState .. " _LuaExecute.txt'" )
146
+ file .Write (" blobsProfiler/" .. luaState .. " _LuaExecute.txt" , value )
147
+ dhtmlPanel .lastCode = value
148
+ end
149
+
114
150
if luaState == " Client" then
115
151
RunString (value )
116
152
elseif luaState == " Server" then
@@ -132,9 +168,30 @@ blobsProfiler.RegisterSubModule("Lua", "Execute", {
132
168
gmod.receiveEditorContent(value);
133
169
]] )
134
170
end
171
+
172
+ dhtmlPanel .attemptSaveContentsToFile = function ()
173
+ dhtmlPanel :RunJavascript ([[
174
+ var value = getEditorValue();
175
+ gmod.saveContentsToFile(value);
176
+ ]] )
177
+ end
178
+
179
+ parentPanel .codePanel = dhtmlPanel
135
180
end
136
181
})
137
182
183
+ timer .Create (" blobsProfiler:LuaExecute_SaveToFile" , 15 , 0 , function () -- TODO: Make this configurable once I do settings - and module settings
184
+ local moduleTbl = blobsProfiler .GetModule (" Lua.Execute" )
185
+ if not moduleTbl then return end
186
+
187
+ if moduleTbl .ClientTab and moduleTbl .ClientTab .codePanel and moduleTbl .ClientTab .codePanel .attemptSaveContentsToFile then
188
+ moduleTbl .ClientTab .codePanel .attemptSaveContentsToFile ()
189
+ end
190
+ if moduleTbl .ServerTab and moduleTbl .ServerTab .codePanel and moduleTbl .ServerTab .codePanel .attemptSaveContentsToFile then
191
+ moduleTbl .ServerTab .codePanel .attemptSaveContentsToFile ()
192
+ end
193
+ end )
194
+
138
195
local function prettyProfilerTimeFormat (seconds )
139
196
if seconds >= 0.5 then
140
197
return string.format (" %.2fs" , seconds )
0 commit comments