MCPcopy Create free account
hub / github.com/clementgallet/libTAS / watchChanges

Method watchChanges

src/program/lua/LuaFunctionList.cpp:86–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84}
85
86void LuaFunctionList::watchChanges()
87{
88 struct inotify_event ev;
89 int ret = read(inotifyfd, &ev, sizeof(struct inotify_event));
90 if (ret < 0) {
91 if (errno != EAGAIN) // no event
92 std::cerr << "Error reading inotify event: " << errno << std::endl;
93 }
94 else {
95 for (size_t i = 0; i < fileList.size(); i++) {
96 if (fileList[i].wd == ev.wd ) {
97 if (ev.mask == IN_MODIFY) {
98 LuaFile& lf = fileList[i];
99
100 /* Reload the file */
101 const std::string& file = lf.file;
102 functions.remove_if([&file](const NamedLuaFunction& nlf){ return 0 == file.compare(nlf.file); });
103
104 /* Create a new lua state */
105 if (lf.lua_state)
106 lua_close(lf.lua_state);
107 lf.lua_state = Main::new_state();
108 Main::run(lf.lua_state, file);
109
110 /* Set again the active state */
111 switchForFile(i, lf.enabled);
112 }
113 else if (ev.mask == IN_IGNORED) {
114 LuaFile& lf = fileList[i];
115
116 const std::filesystem::path& file = lf.file;
117
118 /* File got potentially modified so check if it still exists
119 * Watch descriptor has been removed automatically so don't need to do that manually */
120 lf.wd = inotify_add_watch(inotifyfd, file.c_str(), IN_MODIFY);
121 if (lf.wd < 0) {
122 return;
123 }
124
125 functions.remove_if([&file](const NamedLuaFunction& nlf){ return 0 == file.compare(nlf.file); });
126
127 /* Create a new lua state */
128 if (lf.lua_state)
129 lua_close(lf.lua_state);
130 lf.lua_state = Main::new_state();
131 Main::run(lf.lua_state, file);
132
133 /* Set again the active state */
134 switchForFile(i, lf.enabled);
135 }
136 return;
137 }
138 }
139 }
140}
141
142bool LuaFunctionList::activeState(int row) const
143{

Callers 1

updateMethod · 0.80

Calls 2

sizeMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected