From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 2CD5027373 for ; Mon, 6 Aug 2018 03:18:10 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ha1FyLD2gGpK for ; Mon, 6 Aug 2018 03:18:10 -0400 (EDT) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id D583D22BE0 for ; Mon, 6 Aug 2018 03:18:09 -0400 (EDT) Received: by mail-wm0-f65.google.com with SMTP id o11-v6so12647067wmh.2 for ; Mon, 06 Aug 2018 00:18:09 -0700 (PDT) From: Eugene Blikh Subject: [tarantool-patches] [PATCH tarantool 2/2] Using luaT_tolstring in conversion function, instead lua_tostring Date: Mon, 6 Aug 2018 10:17:00 +0300 Message-Id: <2a49d596262a59a2ee1846d67926bc52a795e048.1533292738.git.bigbes@gmail.com> In-Reply-To: References: In-Reply-To: References: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: Eugine Blikh From: Eugine Blikh We can throw any Lua object as Lua error, but current behaviour won't convert it to string. So diag error's object will have NULL, instead of string. luaT_tolstring honors __tostring metamethod and thus can convert table to it's string representation. For example, old behaviour is: ``` tarantool> fiber.create(error, 'help') LuajitError: help tarantool> fiber.create(error, { message = 'help' }) LuajitError: tarantool> fiber.create(error, setmetatable({ message = 'help' }, { __tostring = function(self) return self.message end })) LuajitError: ``` New behaviour is: ``` tarantool> fiber.create(error, 'help') LuajitError: help tarantool> fiber.create(error, { 'help' }) LuajitError: table: 0x0108fa2790 tarantool> fiber.create(error, setmetatable({ message = 'help' }, { __tostring = function(self) return self.message end })) LuajitError: help ``` It won't break anything, but'll add new behaviour --- src/lua/utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua/utils.c b/src/lua/utils.c index afc44b581..56df2bfb6 100644 --- a/src/lua/utils.c +++ b/src/lua/utils.c @@ -920,7 +920,7 @@ luaT_toerror(lua_State *L) diag_add_error(&fiber()->diag, e); } else { /* Convert Lua error to a Tarantool exception. */ - diag_set(LuajitError, lua_tostring(L, -1)); + diag_set(LuajitError, luaT_tolstring(L, -1, NULL)); } return 1; } -- 2.16.2