Compare commits

...

6 Commits

Author SHA1 Message Date
Lars Mueller 597666f3e3 SQLite3 persistence: Wrap :set in a transaction 2022-08-01 15:00:34 +02:00
Lars Mueller 318e737a08 file: Use io.lines 2022-07-17 21:33:54 +02:00
Lars Mueller b7c6514bc8 Merge branch 'master' of https://github.com/appgurueu/modlib 2022-07-17 21:31:04 +02:00
Lars Müller 017f2119cb
Credit NobWow 2022-07-17 21:28:44 +02:00
NobWow 9f65d5df9a Close the file after reading 2022-07-17 21:27:38 +02:00
Lars Mueller 234f6d1ecd Text inputstream: Allow obtaining cursor position 2022-07-14 15:51:36 +02:00
4 changed files with 16 additions and 13 deletions

View File

@ -4,7 +4,7 @@ Multipurpose Minetest Modding Library
## About
No dependencies. Licensed under the MIT License. Written by Lars Mueller aka LMD or appguru(eu). Notable contributions by [luk3yx](https://github.com/luk3yx) in the form of suggestions, bug reports and fixes.
No dependencies. Licensed under the MIT License. Written by Lars Mueller aka LMD or appguru(eu). Notable contributions by [luk3yx](https://github.com/luk3yx) in the form of suggestions, bug reports and fixes. Another [bugfix](https://github.com/appgurueu/modlib/pull/7) by [NobWow](https://github.com/NobWow/).
## Tests
@ -421,4 +421,4 @@ Fixes, minor additions (such as a `hashheap`)
* Fixes `math.fround`
* Other minor fixes
* Switch to lazy loading
* Do `_ = modlib.<module>` to avoid lag spikes at run time
* Do `_ = modlib.<module>` to avoid lag spikes at run time

View File

@ -121,11 +121,8 @@ end
function process_bridge_listen(name, line_consumer, step)
local bridge = process_bridges[name]
modlib.minetest.register_globalstep(step or 0.1, function()
local content = io.open(bridge.input, "r")
local line = content:read()
while line do
for line in io.lines(bridge.input) do
line_consumer(line)
line = content:read()
end
write(bridge.input, "")
end)
@ -150,4 +147,4 @@ function process_bridge_start(name, command, os_execute)
end
-- Export environment
return _ENV
return _ENV

View File

@ -240,6 +240,7 @@ function ptab:rewrite()
end
function ptab:set(table, key, value)
exec(self, "BEGIN EXCLUSIVE TRANSACTION")
local previous_value = table[key]
if previous_value == value then
-- no change
@ -247,6 +248,7 @@ function ptab:set(table, key, value)
end
set(self, table, key, value)
table[key] = value
exec(self, "COMMIT TRANSACTION")
end
function ptab:set_root(key, value)

View File

@ -62,13 +62,17 @@ function trim_spacing(text)
end
local inputstream_metatable = {
__index = {read = function(self, count)
local cursor = self.cursor + 1
self.cursor = self.cursor + count
local text = self.text:sub(cursor, self.cursor)
return text ~= "" and text or nil
end}
__index = {
read = function(self, count)
local cursor = self.cursor + 1
self.cursor = self.cursor + count
local text = self.text:sub(cursor, self.cursor)
return text ~= "" and text or nil
end,
seek = function(self) return self.cursor end
}
}
--> inputstream "handle"; only allows reading characters (given a count), seeking does not accept any arguments
function inputstream(text)
return setmetatable({text = text, cursor = 0}, inputstream_metatable)
end