Merge pull request #69 from VE-FORBRYDERNE/lua

Lua compatibility enhancements
This commit is contained in:
henk717 2022-01-22 23:23:47 +01:00 committed by GitHub
commit 4e7440804c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 8 deletions

View File

@ -3232,6 +3232,7 @@ def update_story_chunk(idx: Union[int, str]):
# prompt might not have been shown yet (with a "Generating story..."
# message instead).
refresh_story()
setgamesaved(False)
return
idx = (vars.actions.get_last_key() if len(vars.actions) else 0) + 1
@ -3250,6 +3251,8 @@ def update_story_chunk(idx: Union[int, str]):
chunk_text = f'<chunk n="{idx}" id="n{idx}" tabindex="-1">{formatforhtml(item)}</chunk>'
emit('from_server', {'cmd': 'updatechunk', 'data': {'index': idx, 'html': chunk_text}}, broadcast=True)
setgamesaved(False)
#If we've set the auto save flag, we'll now save the file
if vars.autosave and (".json" in vars.savedir):
save()
@ -3260,6 +3263,7 @@ def update_story_chunk(idx: Union[int, str]):
#==================================================================#
def remove_story_chunk(idx: int):
emit('from_server', {'cmd': 'removechunk', 'data': idx}, broadcast=True)
setgamesaved(False)
#==================================================================#

View File

@ -1614,7 +1614,12 @@ return function(_python, _bridged)
error("module '" .. modname .. "' not found:" .. table.concat(errors))
return
end
local retval = old_loadfile(path, "t", env)()
local f, err = old_loadfile(path, "t", env)
if err ~= nil then
error(err)
return
end
local retval = (f())
package_loaded[env][modname] = retval == nil or retval
return package_loaded[env][modname], path
end
@ -1664,12 +1669,33 @@ return function(_python, _bridged)
bridged.print(table.concat(args, "\t"))
end
local function redirected_warn(...)
local args = table.pack(...)
for i = 1, args.n do
args[i] = tostring(args[i])
local function _redirected_warn()
local do_warning = true
local control_table = {
["@on"] = function()
do_warning = true
end,
["@off"] = function()
do_warning = false
end,
}
return function(...)
local args = table.pack(...)
if args.n == 1 and type(args[1]) == "string" and args[1]:sub(1, 1) == "@" then
local f = control_table[args[1]]
if f ~= nil then
f()
end
return
end
if not do_warning then
return
end
for i = 1, args.n do
args[i] = tostring(args[i])
end
bridged.warn(table.concat(args, "\t"))
end
bridged.warn(table.concat(args, "\t"))
end
local sandbox_template_env = {
@ -1829,7 +1855,7 @@ return function(_python, _bridged)
envs[universe].load = _safe_load(env)
envs[universe].require = _safe_require(env)
envs[universe].print = redirected_print
envs[universe].warn = redirected_warn
envs[universe].warn = _redirected_warn()
env._G = env
end
return env