mirror of
https://github.com/aseprite/aseprite.git
synced 2024-10-06 06:50:07 +00:00
[lua] Fix bugs handling errors inside app.transaction()
This errors was reported in #4431: The Tx wasn't rolled back correctly in case of a Lua error inside the transaction because Lua needs to be compiled as C++ to avoid longjmps and support stack unwinding (i.e. calling destructors).
This commit is contained in:
parent
d1ea2eaff1
commit
4d18200b0c
@ -42,6 +42,14 @@
|
|||||||
#include <stack>
|
#include <stack>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
// We use our own fopen() that supports Unicode filename on Windows
|
||||||
|
// extern "C"
|
||||||
|
FILE* lua_user_fopen(const char* fname,
|
||||||
|
const char* mode)
|
||||||
|
{
|
||||||
|
return base::open_file_raw(fname, mode);
|
||||||
|
}
|
||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
namespace script {
|
namespace script {
|
||||||
|
|
||||||
@ -210,13 +218,6 @@ void register_websocket_class(lua_State* L);
|
|||||||
|
|
||||||
void set_app_params(lua_State* L, const Params& params);
|
void set_app_params(lua_State* L, const Params& params);
|
||||||
|
|
||||||
// We use our own fopen() that supports Unicode filename on Windows
|
|
||||||
extern "C" FILE* lua_user_fopen(const char* fname,
|
|
||||||
const char* mode)
|
|
||||||
{
|
|
||||||
return base::open_file_raw(fname, mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
Engine::Engine()
|
Engine::Engine()
|
||||||
: L(luaL_newstate())
|
: L(luaL_newstate())
|
||||||
, m_delegate(nullptr)
|
, m_delegate(nullptr)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2018-2023 Igara Studio S.A.
|
// Copyright (C) 2018-2024 Igara Studio S.A.
|
||||||
// Copyright (C) 2018 David Capello
|
// Copyright (C) 2018 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
@ -9,11 +9,12 @@
|
|||||||
#define APP_SCRIPT_LUACPP_H_INCLUDED
|
#define APP_SCRIPT_LUACPP_H_INCLUDED
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
extern "C" {
|
// We're compiling Lua with C++ support to handle error with
|
||||||
#include "lua.h"
|
// exceptions, so there is no need of extern "C" { ... } these
|
||||||
#include "lualib.h"
|
// includes.
|
||||||
#include "lauxlib.h"
|
#include "lua.h"
|
||||||
}
|
#include "lualib.h"
|
||||||
|
#include "lauxlib.h"
|
||||||
|
|
||||||
#include "base/debug.h"
|
#include "base/debug.h"
|
||||||
|
|
||||||
|
14
third_party/CMakeLists.txt
vendored
14
third_party/CMakeLists.txt
vendored
@ -205,7 +205,19 @@ if(ENABLE_SCRIPTING)
|
|||||||
target_compile_definitions(lua PUBLIC LUA_USE_LINUX=1)
|
target_compile_definitions(lua PUBLIC LUA_USE_LINUX=1)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_compile_definitions(lua PUBLIC LUA_FLOORN2I=1)
|
# Compile Lua as C++ to control errors with exceptions and have
|
||||||
|
# stack unwinding (i.e. calling destructors correctly).
|
||||||
|
if(MSVC)
|
||||||
|
target_compile_options(lua PRIVATE -TP)
|
||||||
|
target_compile_options(lualib PRIVATE -TP)
|
||||||
|
target_compile_options(lauxlib PRIVATE -TP)
|
||||||
|
else()
|
||||||
|
target_compile_options(lua PRIVATE -xc++)
|
||||||
|
target_compile_options(lualib PRIVATE -xc++)
|
||||||
|
target_compile_options(lauxlib PRIVATE -xc++)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_compile_definitions(lua PUBLIC LUA_FLOORN2I=F2Ifloor)
|
||||||
target_compile_definitions(lualib PRIVATE HAVE_SYSTEM)
|
target_compile_definitions(lualib PRIVATE HAVE_SYSTEM)
|
||||||
target_include_directories(lua PUBLIC lua)
|
target_include_directories(lua PUBLIC lua)
|
||||||
target_include_directories(lauxlib PUBLIC lua)
|
target_include_directories(lauxlib PUBLIC lua)
|
||||||
|
Loading…
Reference in New Issue
Block a user