diff options
| -rwxr-xr-x | src/yuescript/yue_compiler.cpp | 2 | ||||
| -rw-r--r-- | src/yuescript/yuescript.h | 42 |
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 | ||
| 61 | typedef std::list<std::string> str_list; | 61 | typedef std::list<std::string> str_list; |
| 62 | 62 | ||
| 63 | const std::string_view version = "0.10.2"sv; | 63 | const std::string_view version = "0.10.3"sv; |
| 64 | const std::string_view extension = "yue"sv; | 64 | const std::string_view extension = "yue"sv; |
| 65 | 65 | ||
| 66 | class YueCompilerImpl { | 66 | class 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 @@ | |||
| 1 | R"yuescript_codes( | 1 | R"yuescript_codes( |
| 2 | --[[ | 2 | --[[ |
| 3 | Copyright (C) 2020 by Leaf Corcoran, modified by Li Jin, 2021 | 3 | Copyright (C) 2020 by Leaf Corcoran, modified by Li Jin, 2022 |
| 4 | 4 | ||
| 5 | Permission is hereby granted, free of charge, to any person obtaining a copy | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | of this software and associated documentation files (the "Software"), to deal | 6 | of 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) |
| 102 | end | 102 | end |
| 103 | yue_loadstring = function(...) | 103 | yue_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 |
| 140 | end | 140 | end |
| 141 | yue.options.dump_locals = false | ||
| 142 | yue.options.simplified = true | ||
| 143 | local load_stacktraceplus = yue.load_stacktraceplus | ||
| 144 | yue.load_stacktraceplus = nil | ||
| 145 | local stp | ||
| 146 | local 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) | ||
| 153 | end | ||
| 141 | local function yue_require(name) | 154 | local 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 |
| 155 | end | 167 | end |
| 156 | local load_stacktraceplus = yue.load_stacktraceplus | ||
| 157 | yue.load_stacktraceplus = nil | ||
| 158 | setmetatable(yue, { | 168 | setmetatable(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 | |||
| 214 | yue.pcall = yue_call | 211 | yue.pcall = yue_call |
| 215 | yue.require = yue_require | 212 | yue.require = yue_require |
| 216 | yue.p = p | 213 | yue.p = p |
| 214 | yue.traceback = yue_traceback | ||
| 217 | )yuescript_codes"; | 215 | )yuescript_codes"; |
