Merge pull request #69 from VE-FORBRYDERNE/lua
Lua compatibility enhancements
This commit is contained in:
commit
4e7440804c
|
@ -3232,6 +3232,7 @@ def update_story_chunk(idx: Union[int, str]):
|
||||||
# prompt might not have been shown yet (with a "Generating story..."
|
# prompt might not have been shown yet (with a "Generating story..."
|
||||||
# message instead).
|
# message instead).
|
||||||
refresh_story()
|
refresh_story()
|
||||||
|
setgamesaved(False)
|
||||||
return
|
return
|
||||||
|
|
||||||
idx = (vars.actions.get_last_key() if len(vars.actions) else 0) + 1
|
idx = (vars.actions.get_last_key() if len(vars.actions) else 0) + 1
|
||||||
|
@ -3249,7 +3250,9 @@ def update_story_chunk(idx: Union[int, str]):
|
||||||
|
|
||||||
chunk_text = f'<chunk n="{idx}" id="n{idx}" tabindex="-1">{formatforhtml(item)}</chunk>'
|
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)
|
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 we've set the auto save flag, we'll now save the file
|
||||||
if vars.autosave and (".json" in vars.savedir):
|
if vars.autosave and (".json" in vars.savedir):
|
||||||
save()
|
save()
|
||||||
|
@ -3260,6 +3263,7 @@ def update_story_chunk(idx: Union[int, str]):
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
def remove_story_chunk(idx: int):
|
def remove_story_chunk(idx: int):
|
||||||
emit('from_server', {'cmd': 'removechunk', 'data': idx}, broadcast=True)
|
emit('from_server', {'cmd': 'removechunk', 'data': idx}, broadcast=True)
|
||||||
|
setgamesaved(False)
|
||||||
|
|
||||||
|
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
|
|
40
bridge.lua
40
bridge.lua
|
@ -1614,7 +1614,12 @@ return function(_python, _bridged)
|
||||||
error("module '" .. modname .. "' not found:" .. table.concat(errors))
|
error("module '" .. modname .. "' not found:" .. table.concat(errors))
|
||||||
return
|
return
|
||||||
end
|
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
|
package_loaded[env][modname] = retval == nil or retval
|
||||||
return package_loaded[env][modname], path
|
return package_loaded[env][modname], path
|
||||||
end
|
end
|
||||||
|
@ -1664,12 +1669,33 @@ return function(_python, _bridged)
|
||||||
bridged.print(table.concat(args, "\t"))
|
bridged.print(table.concat(args, "\t"))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function redirected_warn(...)
|
local function _redirected_warn()
|
||||||
local args = table.pack(...)
|
local do_warning = true
|
||||||
for i = 1, args.n do
|
local control_table = {
|
||||||
args[i] = tostring(args[i])
|
["@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
|
end
|
||||||
bridged.warn(table.concat(args, "\t"))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local sandbox_template_env = {
|
local sandbox_template_env = {
|
||||||
|
@ -1829,7 +1855,7 @@ return function(_python, _bridged)
|
||||||
envs[universe].load = _safe_load(env)
|
envs[universe].load = _safe_load(env)
|
||||||
envs[universe].require = _safe_require(env)
|
envs[universe].require = _safe_require(env)
|
||||||
envs[universe].print = redirected_print
|
envs[universe].print = redirected_print
|
||||||
envs[universe].warn = redirected_warn
|
envs[universe].warn = _redirected_warn()
|
||||||
env._G = env
|
env._G = env
|
||||||
end
|
end
|
||||||
return env
|
return env
|
||||||
|
|
Loading…
Reference in New Issue