Skip to content

Commit

Permalink
Change scripting language to Lua
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Aug 22, 2018
1 parent 70629d6 commit 4fe66f2
Show file tree
Hide file tree
Showing 45 changed files with 1,153 additions and 1,722 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@
[submodule "third_party/benchmark"]
path = third_party/benchmark
url = https://github.com/aseprite/benchmark.git
[submodule "third_party/mujs"]
path = third_party/mujs
url = https://github.com/aseprite/mujs.git
[submodule "third_party/giflib"]
path = third_party/giflib
url = https://github.com/aseprite/giflib.git
Expand All @@ -63,3 +60,6 @@
[submodule "third_party/tinyexpr"]
path = third_party/tinyexpr
url = https://github.com/aseprite/tinyexpr.git
[submodule "third_party/lua"]
path = third_party/lua
url = https://github.com/aseprite/lua
2 changes: 1 addition & 1 deletion data/gui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@
<item command="PasteText" text="@.edit_insert_text" />
<!--menu text="Scripts">
<item command="RunScript" text="Transparency from White Background">
<param name="filename" value="white_to_alpha.js" />
<param name="filename" value="white_to_alpha.lua" />
</item>
</menu-->
<separator />
Expand Down
20 changes: 0 additions & 20 deletions data/scripts/white_to_alpha.js

This file was deleted.

17 changes: 17 additions & 0 deletions data/scripts/white_to_alpha.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Aseprite
-- Copyright (C) 2015-2018 by David Capello

local pc = app.pixelColor
local img = app.activeImage

for y=0,img.height-1 do
for x=0,img.width-1 do
local c = img:getPixel(x, y)
local r = pc.rgbaR(c)
local g = pc.rgbaG(c)
local b = pc.rgbaB(c)
local a = pc.rgbaA(c)
if a > 0 then a = 255 - (r+g+b)/3 end
img:putPixel(x, y, pc.rgba(r, g, b, a))
end
end
31 changes: 18 additions & 13 deletions docs/LICENSES.md
Original file line number Diff line number Diff line change
Expand Up @@ -904,24 +904,29 @@ freely, subject to the following restrictions:
distribution.
```

# [mujs](http://mujs.com/)
# [Lua](https://www.lua.org/)

```
ISC License
Copyright (C) 1994-2018 Lua.org, PUC-Rio.
Copyright (c) 2013, 2017, Artifex Software
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
```

# [pixman](http://www.pixman.org/)
Expand Down
5 changes: 0 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,6 @@ add_subdirectory(ft)
add_subdirectory(she)
add_subdirectory(ui)

if(ENABLE_SCRIPTING)
add_subdirectory(script)
add_definitions(-DENABLE_SCRIPTING)
endif()

if(ENABLE_UPDATER)
add_subdirectory(updater)
endif()
Expand Down
9 changes: 5 additions & 4 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ endif()

set(scripting_files)
if(ENABLE_SCRIPTING)
add_definitions(-DENABLE_SCRIPTING)
set(scripting_files_ui)
if(ENABLE_UI)
set(scripting_files_ui
Expand All @@ -149,10 +150,10 @@ if(ENABLE_SCRIPTING)
set(scripting_files
commands/cmd_run_script.cpp
script/app_object.cpp
script/app_scripting.cpp
script/console_object.cpp
script/engine.cpp
script/image_class.cpp
script/pixel_color_class.cpp
script/luacpp.cpp
script/pixel_color_object.cpp
script/point_class.cpp
script/rectangle_class.cpp
script/selection_class.cpp
Expand Down Expand Up @@ -595,7 +596,7 @@ target_link_libraries(app-lib
tinyexpr)

if(ENABLE_SCRIPTING)
target_link_libraries(app-lib script-lib)
target_link_libraries(app-lib lua lauxlib lualib)
endif()

if(ENABLE_UPDATER)
Expand Down
5 changes: 2 additions & 3 deletions src/app/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@
#include <memory>

#ifdef ENABLE_SCRIPTING
#include "app/script/app_scripting.h"
#include "app/script/engine.h"
#include "app/shell.h"
#include "script/engine_delegate.h"
#endif

#ifdef ENABLE_STEAM
Expand Down Expand Up @@ -353,7 +352,7 @@ void App::run()
// Start shell to execute scripts.
if (m_isShell) {
script::StdoutEngineDelegate delegate;
AppScripting engine(&delegate);
script::Engine engine(&delegate);
engine.printLastResult();
Shell shell;
shell.run(engine);
Expand Down
5 changes: 2 additions & 3 deletions src/app/cli/default_cli_delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
#include "doc/sprite.h"

#ifdef ENABLE_SCRIPTING
#include "app/script/app_scripting.h"
#include "script/engine_delegate.h"
#include "app/script/engine.h"
#endif

#include <iostream>
Expand Down Expand Up @@ -128,7 +127,7 @@ void DefaultCliDelegate::execScript(const std::string& filename)
{
#ifdef ENABLE_SCRIPTING
script::StdoutEngineDelegate delegate;
AppScripting engine(&delegate);
script::Engine engine(&delegate);
if (!engine.evalFile(filename))
throw std::runtime_error("Error executing script");
#endif
Expand Down
5 changes: 2 additions & 3 deletions src/app/commands/cmd_run_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
#include "app/commands/params.h"
#include "app/console.h"
#include "app/resource_finder.h"
#include "app/script/app_scripting.h"
#include "app/script/engine.h"
#include "base/fs.h"
#include "script/engine_delegate.h"
#include "ui/manager.h"

#include <cstdio>
Expand Down Expand Up @@ -67,7 +66,7 @@ void RunScriptCommand::onLoadParams(const Params& params)
void RunScriptCommand::onExecute(Context* context)
{
ConsoleEngineDelegate delegate;
AppScripting engine(&delegate);
script::Engine engine(&delegate);
engine.evalFile(m_filename);

ui::Manager::getDefault()->invalidate();
Expand Down
Loading

0 comments on commit 4fe66f2

Please sign in to comment.