summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2022-02-23 00:22:07 +0800
committerLi Jin <dragon-fly@qq.com>2022-02-23 00:22:07 +0800
commit63878b93b0f142af74b397a02b2c80be039b03ec (patch)
tree7be79ea1d16a6cd5352bb5a4c906f07abf6a65a6 /src
parentb50cffceb63db8b9ea070dc4f1cec6008bb5ff2c (diff)
downloadyuescript-63878b93b0f142af74b397a02b2c80be039b03ec.tar.gz
yuescript-63878b93b0f142af74b397a02b2c80be039b03ec.tar.bz2
yuescript-63878b93b0f142af74b397a02b2c80be039b03ec.zip
add yue.traceback.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/yuescript/yue_compiler.cpp2
-rw-r--r--src/yuescript/yuescript.h42
2 files changed, 21 insertions, 23 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index d1e4d24..274027b 100755
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -60,7 +60,7 @@ using namespace parserlib;
60 60
61typedef std::list<std::string> str_list; 61typedef std::list<std::string> str_list;
62 62
63const std::string_view version = "0.10.2"sv; 63const std::string_view version = "0.10.3"sv;
64const std::string_view extension = "yue"sv; 64const std::string_view extension = "yue"sv;
65 65
66class YueCompilerImpl { 66class YueCompilerImpl {
diff --git a/src/yuescript/yuescript.h b/src/yuescript/yuescript.h
index eac95da..769eb8a 100644
--- a/src/yuescript/yuescript.h
+++ b/src/yuescript/yuescript.h
@@ -1,6 +1,6 @@
1R"yuescript_codes( 1R"yuescript_codes(
2--[[ 2--[[
3Copyright (C) 2020 by Leaf Corcoran, modified by Li Jin, 2021 3Copyright (C) 2020 by Leaf Corcoran, modified by Li Jin, 2022
4 4
5Permission is hereby granted, free of charge, to any person obtaining a copy 5Permission is hereby granted, free of charge, to any person obtaining a copy
6of this software and associated documentation files (the "Software"), to deal 6of this software and associated documentation files (the "Software"), to deal
@@ -97,7 +97,7 @@ local function yue_call(f, ...)
97 return xpcall((function() 97 return xpcall((function()
98 return f(unpack(args)) 98 return f(unpack(args))
99 end), function(err) 99 end), function(err)
100 return yue.stp.stacktrace(err, 1) 100 return yue.traceback(err, 1)
101 end) 101 end)
102end 102end
103yue_loadstring = function(...) 103yue_loadstring = function(...)
@@ -138,37 +138,34 @@ local function insert_loader(pos)
138 insert(loaders, pos, yue_loader) 138 insert(loaders, pos, yue_loader)
139 return true 139 return true
140end 140end
141yue.options.dump_locals = false
142yue.options.simplified = true
143local load_stacktraceplus = yue.load_stacktraceplus
144yue.load_stacktraceplus = nil
145local stp
146local function yue_traceback(err, level)
147 if not stp then
148 stp = load_stacktraceplus()
149 end
150 stp.dump_locals = yue.options.dump_locals
151 stp.simplified = yue.options.simplified
152 return stp.stacktrace(err, level)
153end
141local function yue_require(name) 154local function yue_require(name)
142 insert_loader() 155 insert_loader()
143 local success, res = xpcall((function() 156 local success, res = xpcall(function()
144 return require(name) 157 return require(name)
145 end), function(err) 158 end, function(err)
146 local msg = yue.stp.stacktrace(err, 1) 159 return yue_traceback(err, 2)
147 print(msg)
148 return msg
149 end) 160 end)
150 if success then 161 if success then
151 return res 162 return res
152 else 163 else
164 print(res)
153 return nil 165 return nil
154 end 166 end
155end 167end
156local load_stacktraceplus = yue.load_stacktraceplus
157yue.load_stacktraceplus = nil
158setmetatable(yue, { 168setmetatable(yue, {
159 __index = function(self, key)
160 if not (key == "stp") then
161 return nil
162 end
163 local stp = rawget(yue, "stp")
164 if not stp then
165 stp = load_stacktraceplus()
166 stp.dump_locals = false
167 stp.simplified = true
168 yue.stp = stp
169 end
170 return stp
171 end,
172 __call = function(self, name) 169 __call = function(self, name)
173 return self.require(name) 170 return self.require(name)
174 end 171 end
@@ -214,4 +211,5 @@ yue.loadstring = yue_loadstring
214yue.pcall = yue_call 211yue.pcall = yue_call
215yue.require = yue_require 212yue.require = yue_require
216yue.p = p 213yue.p = p
214yue.traceback = yue_traceback
217)yuescript_codes"; 215)yuescript_codes";