2018-09-27 03:14:16 +00:00
|
|
|
lovr = require 'lovr'
|
|
|
|
|
2018-04-26 03:07:28 +00:00
|
|
|
local function nogame()
|
2017-12-19 00:01:12 +00:00
|
|
|
function lovr.conf(t)
|
2020-09-25 22:41:30 +00:00
|
|
|
t.headset.supersample = true
|
2017-12-19 00:01:12 +00:00
|
|
|
t.modules.audio = false
|
|
|
|
t.modules.physics = false
|
2018-04-26 03:07:28 +00:00
|
|
|
t.modules.thread = false
|
2017-12-19 00:01:12 +00:00
|
|
|
end
|
|
|
|
|
2019-05-09 00:11:25 +00:00
|
|
|
local models = {}
|
|
|
|
|
2017-12-19 00:01:12 +00:00
|
|
|
function lovr.load()
|
2019-04-08 10:25:45 +00:00
|
|
|
if not lovr.graphics then
|
2019-04-08 12:18:28 +00:00
|
|
|
print(string.format('LÖVR %d.%d.%d\nNo game', lovr.getVersion()))
|
2019-04-08 10:25:45 +00:00
|
|
|
lovr.event.quit()
|
|
|
|
return
|
|
|
|
end
|
2019-06-30 01:23:13 +00:00
|
|
|
|
2020-09-26 00:08:51 +00:00
|
|
|
lovr.graphics.setBackgroundColor(0x20232c)
|
|
|
|
lovr.graphics.setCullingEnabled(true)
|
2019-06-30 01:20:32 +00:00
|
|
|
|
2020-09-26 00:08:51 +00:00
|
|
|
logo = lovr.graphics.newShader([[
|
2019-06-30 01:20:32 +00:00
|
|
|
vec4 position(mat4 projection, mat4 transform, vec4 vertex) {
|
|
|
|
return projection * transform * vertex;
|
|
|
|
}
|
|
|
|
]], [[
|
2019-07-03 03:11:39 +00:00
|
|
|
vec4 color(vec4 graphicsColor, sampler2D image, vec2 uv) {
|
2019-06-30 01:20:32 +00:00
|
|
|
float y = (1. - uv.y);
|
|
|
|
uv = uv * 4. - 2.;
|
|
|
|
const float k = sqrt(3.);
|
|
|
|
uv.x = abs(uv.x) - 1.;
|
|
|
|
uv.y = uv.y + 1. / k + .25;
|
|
|
|
if (uv.x + k * uv.y > 0.) {
|
|
|
|
uv = vec2(uv.x - k * uv.y, -k * uv.x - uv.y) / 2.;
|
|
|
|
}
|
|
|
|
uv.x -= clamp(uv.x, -2., 0.);
|
|
|
|
float sdf = -length(uv) * sign(uv.y) - .5;
|
2021-02-23 00:53:47 +00:00
|
|
|
float w = fwidth(sdf) * .5;
|
2019-06-30 01:20:32 +00:00
|
|
|
float alpha = smoothstep(.22 + w, .22 - w, sdf);
|
|
|
|
vec3 color = mix(vec3(.094, .662, .890), vec3(.913, .275, .6), clamp(y * 1.5 - .25, 0., 1.));
|
2020-09-26 00:08:51 +00:00
|
|
|
color = mix(color, vec3(.2, .2, .24), smoothstep(-.12 + w, -.12 - w, sdf));
|
2019-06-30 01:20:32 +00:00
|
|
|
return vec4(pow(color, vec3(2.2)), alpha);
|
|
|
|
}
|
2020-09-26 00:08:51 +00:00
|
|
|
]], { flags = { highp = true } })
|
|
|
|
|
|
|
|
text = lovr.graphics.newShader('font', { flags = { highp = true } })
|
2017-12-19 00:01:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function lovr.draw()
|
2019-06-30 01:20:32 +00:00
|
|
|
lovr.graphics.setColor(0xffffff)
|
2019-05-09 00:11:25 +00:00
|
|
|
|
2017-12-19 00:01:12 +00:00
|
|
|
local padding = .1
|
|
|
|
local font = lovr.graphics.getFont()
|
|
|
|
local fade = .315 + .685 * math.abs(math.sin(lovr.timer.getTime() * 2))
|
2018-03-05 05:46:37 +00:00
|
|
|
local titlePosition = 1.4 - padding
|
2017-12-19 00:01:12 +00:00
|
|
|
local subtitlePosition = titlePosition - font:getHeight() * .25 - padding
|
2019-06-30 01:20:32 +00:00
|
|
|
|
2020-09-26 00:08:51 +00:00
|
|
|
lovr.graphics.setShader(logo)
|
2019-06-30 01:20:32 +00:00
|
|
|
lovr.graphics.plane('fill', 0, 1.9, -3, 1, 1, 0, 0, 1)
|
|
|
|
|
2020-09-26 00:08:51 +00:00
|
|
|
lovr.graphics.setShader(text)
|
|
|
|
lovr.graphics.setColor(0xffffff)
|
2019-06-30 01:20:32 +00:00
|
|
|
lovr.graphics.print('LÖVR', -.012, titlePosition, -3, .25, 0, 0, 1, 0, nil, 'center', 'top')
|
|
|
|
|
2020-09-26 00:08:51 +00:00
|
|
|
lovr.graphics.setColor(.9, .9, .9, fade)
|
2019-06-30 01:20:32 +00:00
|
|
|
lovr.graphics.print('No game :(', -.005, subtitlePosition, -3, .15, 0, 0, 1, 0, nil, 'center', 'top')
|
2020-09-30 04:24:40 +00:00
|
|
|
lovr.graphics.setColor(0xffffff)
|
2020-09-26 00:08:51 +00:00
|
|
|
lovr.graphics.setShader()
|
|
|
|
|
|
|
|
if lovr.headset then
|
|
|
|
for i, hand in ipairs(lovr.headset.getHands()) do
|
|
|
|
models[hand] = models[hand] or lovr.headset.newModel(hand, { animated = true })
|
|
|
|
if models[hand] then
|
|
|
|
lovr.headset.animate(hand, models[hand])
|
|
|
|
|
|
|
|
local pose = mat4(lovr.headset.getPose(hand))
|
2022-03-22 21:19:03 +00:00
|
|
|
if models[hand]:hasJoints() then
|
2020-09-26 00:08:51 +00:00
|
|
|
animated = animated or lovr.graphics.newShader('unlit', { flags = { animated = true } })
|
|
|
|
lovr.graphics.setShader(animated)
|
|
|
|
lovr.graphics.setColorMask()
|
|
|
|
models[hand]:draw(pose)
|
|
|
|
lovr.graphics.setColorMask(true, true, true, true)
|
|
|
|
lovr.graphics.setColor(0, 0, 0, .5)
|
|
|
|
models[hand]:draw(pose)
|
|
|
|
lovr.graphics.setShader()
|
|
|
|
else
|
|
|
|
models[hand]:draw(pose)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-06-30 01:20:32 +00:00
|
|
|
|
|
|
|
lovr.graphics.setColor(0xffffff)
|
2017-12-19 00:01:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-13 06:34:02 +00:00
|
|
|
-- Note: Cannot be overloaded
|
2018-04-26 03:07:28 +00:00
|
|
|
function lovr.boot()
|
|
|
|
local conf = {
|
2021-04-11 14:57:11 +00:00
|
|
|
version = '0.15.0',
|
2019-11-25 01:27:17 +00:00
|
|
|
identity = 'default',
|
2020-06-21 15:02:36 +00:00
|
|
|
saveprecedence = true,
|
2018-04-26 03:07:28 +00:00
|
|
|
modules = {
|
|
|
|
audio = true,
|
|
|
|
data = true,
|
|
|
|
event = true,
|
|
|
|
graphics = true,
|
|
|
|
headset = true,
|
|
|
|
math = true,
|
|
|
|
physics = true,
|
2021-02-25 16:00:12 +00:00
|
|
|
system = true,
|
2018-04-26 03:07:28 +00:00
|
|
|
thread = true,
|
|
|
|
timer = true
|
|
|
|
},
|
2021-02-05 11:48:18 +00:00
|
|
|
audio = {
|
|
|
|
start = true,
|
2021-03-08 05:42:17 +00:00
|
|
|
spatializer = nil
|
2021-02-05 11:48:18 +00:00
|
|
|
},
|
2020-07-28 22:12:15 +00:00
|
|
|
graphics = {
|
|
|
|
debug = false
|
|
|
|
},
|
2018-04-26 03:07:28 +00:00
|
|
|
headset = {
|
2022-03-22 22:47:18 +00:00
|
|
|
drivers = { 'openxr', 'webxr', 'desktop' },
|
2020-09-25 22:41:30 +00:00
|
|
|
supersample = false,
|
2018-07-29 01:12:57 +00:00
|
|
|
offset = 1.7,
|
2020-11-18 00:38:27 +00:00
|
|
|
msaa = 4,
|
|
|
|
overlay = false
|
2018-04-26 03:07:28 +00:00
|
|
|
},
|
2019-06-10 07:11:20 +00:00
|
|
|
math = {
|
2019-07-01 09:16:13 +00:00
|
|
|
globals = true
|
2019-06-10 07:11:20 +00:00
|
|
|
},
|
2018-04-26 03:07:28 +00:00
|
|
|
window = {
|
|
|
|
width = 1080,
|
|
|
|
height = 600,
|
|
|
|
fullscreen = false,
|
2019-08-28 07:56:46 +00:00
|
|
|
resizable = false,
|
2018-04-26 03:07:28 +00:00
|
|
|
msaa = 0,
|
|
|
|
title = 'LÖVR',
|
2019-05-14 07:18:22 +00:00
|
|
|
icon = nil,
|
|
|
|
vsync = 1
|
2018-04-26 03:07:28 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-19 00:01:12 +00:00
|
|
|
|
2018-04-26 03:07:28 +00:00
|
|
|
lovr.filesystem = require('lovr.filesystem')
|
2022-04-23 05:47:49 +00:00
|
|
|
local main = arg[0] and arg[0]:match('[^\\/]-%.lua$') or 'main.lua'
|
|
|
|
local hasConf, hasMain = lovr.filesystem.isFile('conf.lua'), lovr.filesystem.isFile(main)
|
2018-04-26 03:07:28 +00:00
|
|
|
if not lovr.filesystem.getSource() or not (hasConf or hasMain) then nogame() end
|
2017-12-19 00:01:12 +00:00
|
|
|
|
2022-03-28 20:24:44 +00:00
|
|
|
-- Shift args up in fused mode, instead of consuming one for the source path
|
|
|
|
if lovr.filesystem.isFused() then
|
|
|
|
for i = 1, #arg + 1 do
|
|
|
|
arg[i] = arg[i - 1]
|
|
|
|
end
|
|
|
|
arg[0] = lovr.filesystem.getSource()
|
|
|
|
end
|
|
|
|
|
2018-11-23 07:44:56 +00:00
|
|
|
local confOk, confError = true
|
|
|
|
if hasConf then confOk, confError = pcall(require, 'conf') end
|
|
|
|
if confOk and lovr.conf then confOk, confError = pcall(lovr.conf, conf) end
|
2018-04-26 03:07:28 +00:00
|
|
|
|
|
|
|
lovr._setConf(conf)
|
2020-06-21 15:02:36 +00:00
|
|
|
lovr.filesystem.setIdentity(conf.identity, conf.saveprecedence)
|
2017-12-19 00:01:12 +00:00
|
|
|
|
2018-11-16 10:27:34 +00:00
|
|
|
for module in pairs(conf.modules) do
|
2018-04-26 03:07:28 +00:00
|
|
|
if conf.modules[module] then
|
2018-09-27 18:45:43 +00:00
|
|
|
local ok, result = pcall(require, 'lovr.' .. module)
|
2018-11-16 10:27:34 +00:00
|
|
|
if not ok then
|
|
|
|
print(string.format('Warning: Could not load module %q: %s', module, result))
|
|
|
|
else
|
|
|
|
lovr[module] = result
|
|
|
|
end
|
2018-04-26 03:07:28 +00:00
|
|
|
end
|
2017-12-19 00:01:12 +00:00
|
|
|
end
|
|
|
|
|
2020-08-25 21:49:19 +00:00
|
|
|
if lovr.headset and lovr.graphics and conf.window then
|
2021-06-10 23:26:15 +00:00
|
|
|
lovr.headset.start()
|
2020-08-25 21:49:19 +00:00
|
|
|
end
|
|
|
|
|
2018-04-26 03:07:28 +00:00
|
|
|
lovr.handlers = setmetatable({}, { __index = lovr })
|
2018-11-23 07:44:56 +00:00
|
|
|
if not confOk then error(confError) end
|
2022-04-23 05:47:49 +00:00
|
|
|
if hasMain then require(main:gsub('%.lua$', '')) end
|
2018-04-26 03:07:28 +00:00
|
|
|
return lovr.run()
|
2017-12-19 00:01:12 +00:00
|
|
|
end
|
|
|
|
|
2018-04-26 03:07:28 +00:00
|
|
|
function lovr.run()
|
2021-02-09 15:26:44 +00:00
|
|
|
if lovr.timer then lovr.timer.step() end
|
2018-04-26 03:07:28 +00:00
|
|
|
if lovr.load then lovr.load(arg) end
|
|
|
|
return function()
|
2021-02-09 15:26:44 +00:00
|
|
|
if lovr.event then
|
|
|
|
lovr.event.pump()
|
|
|
|
for name, a, b, c, d in lovr.event.poll() do
|
|
|
|
if name == 'restart' then
|
|
|
|
local cookie = lovr.restart and lovr.restart()
|
|
|
|
return 'restart', cookie
|
|
|
|
elseif name == 'quit' and (not lovr.quit or not lovr.quit(a)) then
|
|
|
|
return a or 0
|
|
|
|
end
|
|
|
|
if lovr.handlers[name] then lovr.handlers[name](a, b, c, d) end
|
2018-04-26 03:07:28 +00:00
|
|
|
end
|
2017-12-19 00:01:12 +00:00
|
|
|
end
|
2022-03-23 00:52:16 +00:00
|
|
|
local dt = 0
|
2021-02-09 15:26:44 +00:00
|
|
|
if lovr.timer then dt = lovr.timer.step() end
|
2022-03-23 00:52:16 +00:00
|
|
|
if lovr.headset then dt = lovr.headset.update() end
|
2018-04-26 03:07:28 +00:00
|
|
|
if lovr.update then lovr.update(dt) end
|
|
|
|
if lovr.graphics then
|
|
|
|
lovr.graphics.origin()
|
2021-02-05 22:03:06 +00:00
|
|
|
if lovr.headset then
|
|
|
|
lovr.headset.renderTo(lovr.draw)
|
|
|
|
end
|
|
|
|
if lovr.graphics.hasWindow() then
|
|
|
|
lovr.mirror()
|
2018-04-26 03:07:28 +00:00
|
|
|
end
|
|
|
|
lovr.graphics.present()
|
|
|
|
end
|
2021-02-09 15:26:44 +00:00
|
|
|
if lovr.math then lovr.math.drain() end
|
2017-12-19 00:01:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-24 21:20:14 +00:00
|
|
|
function lovr.mirror()
|
2019-01-25 20:08:45 +00:00
|
|
|
if lovr.headset then -- On some systems, headset module will be disabled
|
2020-10-27 07:41:14 +00:00
|
|
|
local blend, alpha = lovr.graphics.getBlendMode()
|
|
|
|
lovr.graphics.setBlendMode()
|
2019-01-25 20:08:45 +00:00
|
|
|
local texture = lovr.headset.getMirrorTexture()
|
|
|
|
if texture then -- On some drivers, texture is printed directly to the window
|
2022-03-22 21:11:33 +00:00
|
|
|
lovr.graphics.fill(texture)
|
2019-01-25 20:08:45 +00:00
|
|
|
end
|
2020-10-27 07:41:14 +00:00
|
|
|
lovr.graphics.setBlendMode(blend, alpha)
|
2019-01-24 21:20:14 +00:00
|
|
|
else
|
|
|
|
lovr.graphics.clear()
|
2021-02-05 22:03:06 +00:00
|
|
|
if lovr.draw then
|
|
|
|
lovr.draw()
|
|
|
|
end
|
2019-01-24 21:20:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-13 06:34:02 +00:00
|
|
|
local function formatTraceback(s)
|
|
|
|
return s:gsub('\n[^\n]+$', ''):gsub('\t', ''):gsub('stack traceback', '\nStack')
|
|
|
|
end
|
|
|
|
|
|
|
|
function lovr.errhand(message, traceback)
|
2018-11-23 07:44:56 +00:00
|
|
|
message = tostring(message)
|
2019-08-01 07:14:37 +00:00
|
|
|
message = message .. formatTraceback(traceback or debug.traceback('', 4))
|
|
|
|
print('Error:\n' .. message)
|
2018-05-14 00:27:28 +00:00
|
|
|
if not lovr.graphics then return function() return 1 end end
|
2019-08-01 07:14:37 +00:00
|
|
|
|
2018-04-26 03:07:28 +00:00
|
|
|
lovr.graphics.reset()
|
2019-08-19 21:52:56 +00:00
|
|
|
lovr.graphics.setBackgroundColor(.11, .10, .14)
|
|
|
|
lovr.graphics.setColor(.85, .85, .85)
|
2018-04-26 03:07:28 +00:00
|
|
|
local font = lovr.graphics.getFont()
|
2020-08-19 03:15:31 +00:00
|
|
|
font:setPixelDensity()
|
2019-04-13 22:40:09 +00:00
|
|
|
font:setFlipEnabled(false)
|
2019-08-19 21:52:56 +00:00
|
|
|
local wrap = .7 * font:getPixelDensity()
|
|
|
|
local width, lines = font:getWidth(message, wrap)
|
|
|
|
local height = 2.6 + lines
|
|
|
|
local y = math.min(height / 2, 10)
|
2020-08-19 20:01:31 +00:00
|
|
|
local function render()
|
2019-08-19 21:52:56 +00:00
|
|
|
lovr.graphics.print('Error', -width / 2, y, -20, 1.6, 0, 0, 0, 0, nil, 'left', 'top')
|
|
|
|
lovr.graphics.print(message, -width / 2, y - 2.6, -20, 1.0, 0, 0, 0, 0, wrap, 'left', 'top')
|
2018-04-26 03:07:28 +00:00
|
|
|
end
|
2019-08-01 07:14:37 +00:00
|
|
|
|
2018-04-26 03:07:28 +00:00
|
|
|
return function()
|
|
|
|
lovr.event.pump()
|
2020-08-04 18:21:38 +00:00
|
|
|
for name, a in lovr.event.poll() do
|
|
|
|
if name == 'quit' then return a or 1
|
|
|
|
elseif name == 'restart' then return 'restart', lovr.restart and lovr.restart() end
|
|
|
|
end
|
2018-04-26 03:07:28 +00:00
|
|
|
lovr.graphics.origin()
|
2019-09-03 22:34:41 +00:00
|
|
|
if lovr.headset then
|
2022-03-23 00:52:16 +00:00
|
|
|
lovr.headset.update()
|
2019-09-03 22:34:41 +00:00
|
|
|
lovr.headset.renderTo(render)
|
|
|
|
end
|
2019-07-03 01:42:33 +00:00
|
|
|
if lovr.graphics.hasWindow() then
|
2020-09-25 02:03:37 +00:00
|
|
|
lovr.graphics.setViewPose(1)
|
|
|
|
local width, height = lovr.graphics.getDimensions()
|
2020-11-21 02:23:04 +00:00
|
|
|
local projection = lovr.math.mat4():perspective(.1, 100, math.rad(67), width / height)
|
2020-09-25 02:03:37 +00:00
|
|
|
lovr.graphics.setProjection(1, projection)
|
2019-07-03 01:42:33 +00:00
|
|
|
lovr.graphics.clear()
|
2020-08-19 20:01:31 +00:00
|
|
|
render()
|
2019-07-03 01:42:33 +00:00
|
|
|
end
|
2018-04-26 03:07:28 +00:00
|
|
|
lovr.graphics.present()
|
2020-11-18 20:37:31 +00:00
|
|
|
if lovr.math then
|
|
|
|
lovr.math.drain()
|
|
|
|
end
|
2017-12-19 00:01:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-12 17:37:45 +00:00
|
|
|
function lovr.threaderror(thread, err)
|
2018-04-26 03:07:28 +00:00
|
|
|
error('Thread error\n\n' .. err, 0)
|
2018-03-12 17:37:45 +00:00
|
|
|
end
|
|
|
|
|
lovr.log;
lovr.log is a new callback that is invoked whenever LÖVR wants to
send the project a message. For example, this could be a performance
warning from the graphics module, an error message from one of the
headset backends, or an API deprecation notice.
The callback's signature is (message, level, tag). The message is a
string containing the message to log, level is a string that is currently
one of "debug", "info", "warn", "error", and tag is an optional string
that is used to indicate the source of the message for grouping purposes.
The default implementation of the callback just prints the message,
but the callback can be overridden to do things like filter messages,
write them to a file, or even render them in VR. Projects can also
invoke the callback directly to log their own messages.
2020-07-06 22:20:55 +00:00
|
|
|
function lovr.log(message, level, tag)
|
2020-07-29 20:24:57 +00:00
|
|
|
message = message:gsub('\n$', '')
|
lovr.log;
lovr.log is a new callback that is invoked whenever LÖVR wants to
send the project a message. For example, this could be a performance
warning from the graphics module, an error message from one of the
headset backends, or an API deprecation notice.
The callback's signature is (message, level, tag). The message is a
string containing the message to log, level is a string that is currently
one of "debug", "info", "warn", "error", and tag is an optional string
that is used to indicate the source of the message for grouping purposes.
The default implementation of the callback just prints the message,
but the callback can be overridden to do things like filter messages,
write them to a file, or even render them in VR. Projects can also
invoke the callback directly to log their own messages.
2020-07-06 22:20:55 +00:00
|
|
|
print(message)
|
|
|
|
end
|
|
|
|
|
2018-11-13 06:34:02 +00:00
|
|
|
-- This splits up the string returned by luax_getstack so it looks like the error message plus the string from
|
|
|
|
-- debug.traceback(). This includes splitting on the newline before 'stack traceback:' and appending a newline
|
|
|
|
local function splitOnLabelLine(s, t)
|
|
|
|
local at = s:reverse():find(t:reverse())
|
|
|
|
if at then
|
|
|
|
local slen = #s
|
|
|
|
at = (#s - at - #t + 2)
|
|
|
|
return s:sub(1, at-2), s:sub(at,slen) .. '\n'
|
|
|
|
else
|
|
|
|
return s, ''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- lovr will run this function in its own coroutine
|
2018-04-26 03:07:28 +00:00
|
|
|
return function()
|
2018-11-13 06:34:02 +00:00
|
|
|
local errored = false -- lovr.errhand may only be called once
|
|
|
|
local function onerror(e, tb) -- wrapper for errhand to ensure it is only called once
|
|
|
|
local function abortclean()
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
if not errored then
|
|
|
|
errored = true
|
|
|
|
return lovr.errhand(e, tb) or abortclean
|
|
|
|
else
|
2018-11-14 03:56:29 +00:00
|
|
|
print('Error occurred while trying to display another error:\n' ..
|
2018-11-23 07:44:56 +00:00
|
|
|
tostring(e) .. formatTraceback(tb or debug.traceback('', 2)))
|
2018-11-13 06:34:02 +00:00
|
|
|
return abortclean
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Executes lovr.boot and lovr.run.
|
|
|
|
-- continuation, afterward, will be either lovr.run's per-frame function, or the result of errhand.
|
|
|
|
local _, continuation = xpcall(lovr.boot, onerror)
|
2018-04-26 03:07:28 +00:00
|
|
|
|
|
|
|
while true do
|
2018-11-13 06:34:02 +00:00
|
|
|
if type(continuation) == 'string' then -- LuaJIT returns a fixed string if an error occurs in an xpcall error handler
|
2019-08-03 03:29:28 +00:00
|
|
|
print('Error occurred while trying to display another error: ' .. continuation)
|
2018-11-13 06:34:02 +00:00
|
|
|
return 1
|
|
|
|
end
|
2018-04-26 03:07:28 +00:00
|
|
|
|
2020-02-26 22:40:40 +00:00
|
|
|
local ok, result, extra = xpcall(continuation, onerror)
|
|
|
|
if result and ok then return result, extra -- Result is value returned by function. Return it.
|
2018-11-23 07:44:56 +00:00
|
|
|
elseif not ok then continuation = result end -- Result is value returned by error handler. Make it the new error handler.
|
|
|
|
|
2018-11-13 06:34:02 +00:00
|
|
|
local externerror = coroutine.yield() -- Return control to C code
|
|
|
|
|
|
|
|
if externerror then -- A must-report error occurred in the C code
|
|
|
|
local errorpart, tracepart = splitOnLabelLine(externerror, 'stack traceback:')
|
|
|
|
continuation = onerror(errorpart, tracepart) -- Switch continuation to lovr.errhand
|
|
|
|
end
|
|
|
|
end
|
2017-12-19 00:01:12 +00:00
|
|
|
end
|