2007-01-15 23:19:50 +01:00
|
|
|
// Copyright (c) 2006, 2007, Niels Martin Hansen
|
2006-12-28 22:18:35 +01:00
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
2006-12-28 22:18:35 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file auto4_lua.cpp
|
|
|
|
/// @brief Lua 5.1-based scripting engine
|
|
|
|
/// @ingroup scripting
|
|
|
|
///
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2008-03-05 00:17:07 +01:00
|
|
|
#ifdef WITH_AUTO4_LUA
|
2007-12-31 07:46:22 +01:00
|
|
|
|
2011-09-28 21:48:37 +02:00
|
|
|
#include "auto4_lua.h"
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#ifndef AGI_PRE
|
2011-09-28 21:48:37 +02:00
|
|
|
#include <cassert>
|
2009-09-10 15:06:40 +02:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <wx/filefn.h>
|
|
|
|
#include <wx/filename.h>
|
|
|
|
#include <wx/log.h>
|
|
|
|
#include <wx/msgdlg.h>
|
2010-01-24 20:07:34 +01:00
|
|
|
#include <wx/tokenzr.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#include <wx/window.h>
|
|
|
|
#endif
|
|
|
|
|
2010-06-09 01:21:39 +02:00
|
|
|
#include <libaegisub/log.h>
|
2011-09-28 21:48:37 +02:00
|
|
|
#include <libaegisub/scoped_ptr.h>
|
2010-06-09 01:21:39 +02:00
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
#include "ass_dialogue.h"
|
|
|
|
#include "ass_file.h"
|
|
|
|
#include "ass_override.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "ass_style.h"
|
|
|
|
#include "auto4_lua_factory.h"
|
|
|
|
#include "auto4_lua_scriptreader.h"
|
2010-05-21 03:13:36 +02:00
|
|
|
#include "main.h"
|
2010-01-24 20:07:34 +01:00
|
|
|
#include "standard_paths.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "text_file_reader.h"
|
2011-09-28 21:48:37 +02:00
|
|
|
#include "utils.h"
|
2008-09-10 18:53:23 +02:00
|
|
|
#include "video_context.h"
|
2008-03-05 05:10:20 +01:00
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
// This must be below the headers above.
|
2008-03-05 05:10:20 +01:00
|
|
|
#ifdef __WINDOWS__
|
2009-03-14 21:52:01 +01:00
|
|
|
#include "../../contrib/lua51/src/lualib.h"
|
|
|
|
#include "../../contrib/lua51/src/lauxlib.h"
|
2008-03-05 05:10:20 +01:00
|
|
|
#else
|
2009-09-10 15:06:40 +02:00
|
|
|
#include <lualib.h>
|
|
|
|
#include <lauxlib.h>
|
2008-03-05 05:10:20 +01:00
|
|
|
#endif
|
|
|
|
|
2011-09-28 21:48:37 +02:00
|
|
|
namespace {
|
|
|
|
void push_value(lua_State *L, lua_CFunction fn) {
|
|
|
|
lua_pushcfunction(L, fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
void push_value(lua_State *L, int n) {
|
|
|
|
lua_pushinteger(L, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
void push_value(lua_State *L, double n) {
|
|
|
|
lua_pushnumber(L, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
void set_field(lua_State *L, const char *name, T value) {
|
|
|
|
push_value(L, value);
|
|
|
|
lua_setfield(L, -2, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString get_global_string(lua_State *L, const char *name) {
|
|
|
|
lua_getglobal(L, name);
|
|
|
|
wxString ret;
|
|
|
|
if (lua_isstring(L, -1))
|
|
|
|
ret = wxString(lua_tostring(L, -1), wxConvUTF8);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
namespace Automation4 {
|
|
|
|
|
|
|
|
// LuaStackcheck
|
2007-02-20 03:50:40 +01:00
|
|
|
#if 0
|
2006-12-28 22:18:35 +01:00
|
|
|
struct LuaStackcheck {
|
|
|
|
lua_State *L;
|
|
|
|
int startstack;
|
2008-03-09 22:09:51 +01:00
|
|
|
void check_stack(int additional)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
|
|
|
int top = lua_gettop(L);
|
|
|
|
if (top - additional != startstack) {
|
2010-06-09 01:21:39 +02:00
|
|
|
LOG_D("automation/lua") << "lua stack size mismatch.";
|
2006-12-28 22:18:35 +01:00
|
|
|
dump();
|
|
|
|
assert(top - additional == startstack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void dump()
|
|
|
|
{
|
|
|
|
int top = lua_gettop(L);
|
2010-06-09 01:21:39 +02:00
|
|
|
LOG_D("automation/lua/stackdump") << "--- dumping lua stack...";
|
2006-12-28 22:18:35 +01:00
|
|
|
for (int i = top; i > 0; i--) {
|
|
|
|
lua_pushvalue(L, i);
|
|
|
|
wxString type(lua_typename(L, lua_type(L, -1)), wxConvUTF8);
|
|
|
|
if (lua_isstring(L, i)) {
|
2010-06-09 01:21:39 +02:00
|
|
|
LOG_D("automation/lua/stackdump") << type << ": " << luatostring(L, -1);
|
2006-12-28 22:18:35 +01:00
|
|
|
} else {
|
2010-06-09 01:21:39 +02:00
|
|
|
LOG_D("automation/lua/stackdump") << type;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
2010-06-09 01:21:39 +02:00
|
|
|
LOG_D("automation/lua") << "--- end dump";
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
LuaStackcheck(lua_State *_L) : L(_L) { startstack = lua_gettop(L); }
|
2008-03-09 22:09:51 +01:00
|
|
|
~LuaStackcheck() { check_stack(0); }
|
2006-12-28 22:18:35 +01:00
|
|
|
};
|
|
|
|
#else
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// DOCME
|
2006-12-28 22:18:35 +01:00
|
|
|
struct LuaStackcheck {
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief DOCME
|
|
|
|
/// @param additional
|
|
|
|
///
|
2008-03-09 22:09:51 +01:00
|
|
|
void check_stack(int additional) { }
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief DOCME
|
|
|
|
///
|
2006-12-28 22:18:35 +01:00
|
|
|
void dump() { }
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief DOCME
|
|
|
|
/// @param L
|
|
|
|
///
|
2006-12-28 22:18:35 +01:00
|
|
|
LuaStackcheck(lua_State *L) { }
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief DOCME
|
|
|
|
///
|
2006-12-28 22:18:35 +01:00
|
|
|
~LuaStackcheck() { }
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// LuaScript
|
2011-09-28 21:48:37 +02:00
|
|
|
LuaScript::LuaScript(wxString const& filename)
|
|
|
|
: Script(filename)
|
|
|
|
, L(0)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
2007-02-14 01:43:01 +01:00
|
|
|
Create();
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
LuaScript::~LuaScript()
|
|
|
|
{
|
2011-09-28 21:48:37 +02:00
|
|
|
Destroy();
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LuaScript::Create()
|
|
|
|
{
|
|
|
|
Destroy();
|
|
|
|
|
|
|
|
try {
|
|
|
|
// create lua environment
|
|
|
|
L = lua_open();
|
|
|
|
LuaStackcheck _stackcheck(L);
|
|
|
|
|
|
|
|
// register standard libs
|
|
|
|
lua_pushcfunction(L, luaopen_base); lua_call(L, 0, 0);
|
|
|
|
lua_pushcfunction(L, luaopen_package); lua_call(L, 0, 0);
|
|
|
|
lua_pushcfunction(L, luaopen_string); lua_call(L, 0, 0);
|
|
|
|
lua_pushcfunction(L, luaopen_table); lua_call(L, 0, 0);
|
|
|
|
lua_pushcfunction(L, luaopen_math); lua_call(L, 0, 0);
|
2007-01-19 12:47:37 +01:00
|
|
|
lua_pushcfunction(L, luaopen_io); lua_call(L, 0, 0);
|
|
|
|
lua_pushcfunction(L, luaopen_os); lua_call(L, 0, 0);
|
2008-03-09 22:09:51 +01:00
|
|
|
_stackcheck.check_stack(0);
|
2006-12-28 22:18:35 +01:00
|
|
|
// dofile and loadfile are replaced with include
|
|
|
|
lua_pushnil(L);
|
|
|
|
lua_setglobal(L, "dofile");
|
|
|
|
lua_pushnil(L);
|
|
|
|
lua_setglobal(L, "loadfile");
|
|
|
|
lua_pushcfunction(L, LuaInclude);
|
|
|
|
lua_setglobal(L, "include");
|
|
|
|
|
2010-01-24 20:07:34 +01:00
|
|
|
// add include_path to the module load path
|
|
|
|
lua_getglobal(L, "package");
|
|
|
|
lua_pushstring(L, "path");
|
|
|
|
lua_pushstring(L, "path");
|
|
|
|
lua_gettable(L, -3);
|
|
|
|
|
2011-09-28 21:43:11 +02:00
|
|
|
wxStringTokenizer toker(lagi_wxString(OPT_GET("Path/Automation/Include")->GetString()), "|", wxTOKEN_STRTOK);
|
2010-01-24 20:07:34 +01:00
|
|
|
while (toker.HasMoreTokens()) {
|
|
|
|
wxFileName path(StandardPaths::DecodePath(toker.GetNextToken()));
|
|
|
|
if (path.IsOk() && !path.IsRelative() && path.DirExists()) {
|
|
|
|
wxCharBuffer p = path.GetLongPath().utf8_str();
|
2010-01-28 02:13:13 +01:00
|
|
|
lua_pushfstring(L, ";%s?.lua;%s?/init.lua", p.data(), p.data());
|
2010-01-24 20:07:34 +01:00
|
|
|
lua_concat(L, 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lua_settable(L, -3);
|
2010-01-28 02:13:13 +01:00
|
|
|
|
2011-09-28 21:48:37 +02:00
|
|
|
// Replace the default lua module loader with our unicode compatible one
|
2010-01-28 02:13:13 +01:00
|
|
|
lua_getfield(L, -1, "loaders");
|
|
|
|
lua_pushcfunction(L, LuaModuleLoader);
|
|
|
|
lua_rawseti(L, -2, 2);
|
|
|
|
lua_pop(L, 2);
|
2010-01-24 20:07:34 +01:00
|
|
|
_stackcheck.check_stack(0);
|
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
// prepare stuff in the registry
|
|
|
|
// reference to the script object
|
|
|
|
lua_pushlightuserdata(L, this);
|
|
|
|
lua_setfield(L, LUA_REGISTRYINDEX, "aegisub");
|
|
|
|
// the "feature" table
|
|
|
|
// integer indexed, using same indexes as "features" vector in the base Script class
|
|
|
|
lua_newtable(L);
|
|
|
|
lua_setfield(L, LUA_REGISTRYINDEX, "features");
|
2008-03-09 22:09:51 +01:00
|
|
|
_stackcheck.check_stack(0);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
|
|
|
// make "aegisub" table
|
|
|
|
lua_pushstring(L, "aegisub");
|
|
|
|
lua_newtable(L);
|
2011-09-28 21:48:37 +02:00
|
|
|
|
|
|
|
set_field(L, "register_macro", LuaFeatureMacro::LuaRegister);
|
|
|
|
set_field(L, "register_filter", LuaFeatureFilter::LuaRegister);
|
|
|
|
set_field(L, "text_extents", LuaTextExtents);
|
|
|
|
set_field(L, "frame_from_ms", LuaFrameFromMs);
|
|
|
|
set_field(L, "ms_from_frame", LuaMsFromFrame);
|
|
|
|
set_field(L, "video_size", LuaVideoSize);
|
|
|
|
set_field(L, "lua_automation_version", 4);
|
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
// store aegisub table to globals
|
|
|
|
lua_settable(L, LUA_GLOBALSINDEX);
|
2008-03-09 22:09:51 +01:00
|
|
|
_stackcheck.check_stack(0);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
|
|
|
// load user script
|
2007-01-03 04:39:15 +01:00
|
|
|
LuaScriptReader script_reader(GetFilename());
|
2011-09-28 21:48:37 +02:00
|
|
|
if (lua_load(L, script_reader.reader_func, &script_reader, GetPrettyFilename().utf8_str())) {
|
2010-02-25 22:45:39 +01:00
|
|
|
wxString err(lua_tostring(L, -1), wxConvUTF8);
|
2011-09-28 21:43:11 +02:00
|
|
|
err.Prepend("Error loading Lua script \"" + GetPrettyFilename() + "\":\n\n");
|
2011-09-28 21:48:28 +02:00
|
|
|
throw ScriptLoadError(STD_STR(err));
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
2008-03-09 22:09:51 +01:00
|
|
|
_stackcheck.check_stack(1);
|
2011-09-28 21:48:37 +02:00
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
// and execute it
|
|
|
|
// this is where features are registered
|
2007-04-22 17:45:29 +02:00
|
|
|
// don't thread this, as there's no point in it and it seems to break on wx 2.8.3, for some reason
|
|
|
|
if (lua_pcall(L, 0, 0, 0)) {
|
|
|
|
// error occurred, assumed to be on top of Lua stack
|
2010-02-25 22:45:39 +01:00
|
|
|
wxString err(lua_tostring(L, -1), wxConvUTF8);
|
2011-09-28 21:43:11 +02:00
|
|
|
err.Prepend("Error initialising Lua script \"" + GetPrettyFilename() + "\":\n\n");
|
2011-09-28 21:48:28 +02:00
|
|
|
throw ScriptLoadError(STD_STR(err));
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
2008-03-09 22:09:51 +01:00
|
|
|
_stackcheck.check_stack(0);
|
2011-09-28 21:48:37 +02:00
|
|
|
|
2006-12-28 23:55:41 +01:00
|
|
|
lua_getglobal(L, "version");
|
2011-09-28 21:48:37 +02:00
|
|
|
if (lua_isnumber(L, -1) && lua_tointeger(L, -1) == 3) {
|
|
|
|
lua_pop(L, 1); // just to avoid tripping the stackcheck in debug
|
2011-09-28 21:48:28 +02:00
|
|
|
throw ScriptLoadError("Attempted to load an Automation 3 script as an Automation 4 Lua script. Automation 3 is no longer supported.");
|
2006-12-28 23:55:41 +01:00
|
|
|
}
|
2011-09-28 21:48:37 +02:00
|
|
|
|
|
|
|
name = get_global_string(L, "script_name");
|
|
|
|
description = get_global_string(L, "script_description");
|
|
|
|
author = get_global_string(L, "script_author");
|
|
|
|
version = get_global_string(L, "script_version");
|
|
|
|
|
|
|
|
if (name.empty())
|
2007-02-14 01:43:01 +01:00
|
|
|
name = GetPrettyFilename();
|
2011-09-28 21:48:37 +02:00
|
|
|
|
|
|
|
lua_pop(L, 1);
|
2006-12-28 22:18:35 +01:00
|
|
|
// if we got this far, the script should be ready
|
2008-03-09 22:09:51 +01:00
|
|
|
_stackcheck.check_stack(0);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
|
|
|
}
|
2011-09-28 21:48:28 +02:00
|
|
|
catch (agi::Exception const& e) {
|
2007-02-14 01:43:01 +01:00
|
|
|
Destroy();
|
|
|
|
name = GetPrettyFilename();
|
2011-09-28 21:48:28 +02:00
|
|
|
description = e.GetChainedMessage();
|
2007-02-14 01:43:01 +01:00
|
|
|
}
|
2011-09-28 21:48:37 +02:00
|
|
|
}
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
void LuaScript::Destroy()
|
|
|
|
{
|
|
|
|
// Assume the script object is clean if there's no Lua state
|
|
|
|
if (!L) return;
|
|
|
|
|
2011-09-28 21:48:37 +02:00
|
|
|
delete_clear(features);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
|
|
|
lua_close(L);
|
|
|
|
L = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LuaScript::Reload()
|
|
|
|
{
|
|
|
|
Create();
|
|
|
|
}
|
|
|
|
|
|
|
|
LuaScript* LuaScript::GetScriptObject(lua_State *L)
|
|
|
|
{
|
|
|
|
lua_getfield(L, LUA_REGISTRYINDEX, "aegisub");
|
|
|
|
void *ptr = lua_touserdata(L, -1);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
return (LuaScript*)ptr;
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:48:37 +02:00
|
|
|
int LuaScript::RegisterFeature(Feature *feature) {
|
|
|
|
features.push_back(feature);
|
|
|
|
return features.size() - 1;
|
|
|
|
}
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
int LuaScript::LuaTextExtents(lua_State *L)
|
|
|
|
{
|
2011-09-28 21:48:37 +02:00
|
|
|
if (!lua_istable(L, 1))
|
|
|
|
return luaL_error(L, "First argument to text_extents must be a table");
|
|
|
|
|
|
|
|
if (!lua_isstring(L, 2))
|
|
|
|
return luaL_error(L, "Second argument to text_extents must be a string");
|
2006-12-28 22:18:35 +01:00
|
|
|
|
|
|
|
lua_pushvalue(L, 1);
|
2011-09-28 21:48:37 +02:00
|
|
|
agi::scoped_ptr<AssEntry> et(LuaAssFile::LuaToAssEntry(L));
|
|
|
|
AssStyle *st = dynamic_cast<AssStyle*>(et.get());
|
2006-12-28 22:18:35 +01:00
|
|
|
lua_pop(L, 1);
|
2011-09-28 21:48:37 +02:00
|
|
|
if (!st)
|
|
|
|
return luaL_error(L, "Not a style entry");
|
2006-12-28 22:18:35 +01:00
|
|
|
|
|
|
|
wxString text(lua_tostring(L, 2), wxConvUTF8);
|
|
|
|
|
2007-01-15 18:02:39 +01:00
|
|
|
double width, height, descent, extlead;
|
2011-09-28 21:48:37 +02:00
|
|
|
if (!CalculateTextExtents(st, text, width, height, descent, extlead))
|
|
|
|
return luaL_error(L, "Some internal error occurred calculating text_extents");
|
2006-12-28 22:18:35 +01:00
|
|
|
|
|
|
|
lua_pushnumber(L, width);
|
|
|
|
lua_pushnumber(L, height);
|
|
|
|
lua_pushnumber(L, descent);
|
|
|
|
lua_pushnumber(L, extlead);
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
2010-01-28 02:13:13 +01:00
|
|
|
/// @brief Module loader which uses our include rather than Lua's, for unicode file support
|
|
|
|
/// @param L The Lua state
|
|
|
|
/// @return Always 1 per loader_Lua?
|
|
|
|
int LuaScript::LuaModuleLoader(lua_State *L)
|
|
|
|
{
|
|
|
|
int pretop = lua_gettop(L);
|
|
|
|
wxString module(lua_tostring(L, -1), wxConvUTF8);
|
|
|
|
module.Replace(".", LUA_DIRSEP);
|
|
|
|
|
|
|
|
lua_getglobal(L, "package");
|
|
|
|
lua_pushstring(L, "path");
|
|
|
|
lua_gettable(L, -2);
|
|
|
|
wxString package_paths(lua_tostring(L, -1), wxConvUTF8);
|
|
|
|
lua_pop(L, 2);
|
|
|
|
|
2011-09-28 21:43:11 +02:00
|
|
|
wxStringTokenizer toker(package_paths, ";", wxTOKEN_STRTOK);
|
2010-01-28 02:13:13 +01:00
|
|
|
while (toker.HasMoreTokens()) {
|
|
|
|
wxString filename = toker.GetNextToken();
|
2011-09-28 21:43:11 +02:00
|
|
|
filename.Replace("?", module);
|
2010-01-28 02:13:13 +01:00
|
|
|
if (wxFileName::FileExists(filename)) {
|
|
|
|
LuaScriptReader script_reader(filename);
|
|
|
|
if (lua_load(L, script_reader.reader_func, &script_reader, filename.utf8_str())) {
|
2011-09-28 21:48:37 +02:00
|
|
|
return luaL_error(L, "Error loading Lua module \"%s\":\n\n%s", filename.utf8_str().data(), lua_tostring(L, -1));
|
2010-01-28 02:13:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lua_gettop(L) - pretop;
|
|
|
|
}
|
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
int LuaScript::LuaInclude(lua_State *L)
|
|
|
|
{
|
|
|
|
LuaScript *s = GetScriptObject(L);
|
|
|
|
|
2011-09-28 21:48:37 +02:00
|
|
|
if (!lua_isstring(L, 1))
|
|
|
|
return luaL_error(L, "Argument to include must be a string");
|
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
wxString fnames(lua_tostring(L, 1), wxConvUTF8);
|
|
|
|
|
|
|
|
wxFileName fname(fnames);
|
|
|
|
if (fname.GetDirCount() == 0) {
|
|
|
|
// filename only
|
|
|
|
fname = s->include_path.FindAbsoluteValidPath(fnames);
|
|
|
|
} else if (fname.IsRelative()) {
|
|
|
|
// relative path
|
|
|
|
wxFileName sfname(s->GetFilename());
|
|
|
|
fname.MakeAbsolute(sfname.GetPath(true));
|
|
|
|
} else {
|
|
|
|
// absolute path, do nothing
|
|
|
|
}
|
2011-09-28 21:48:37 +02:00
|
|
|
if (!fname.IsOk() || !fname.FileExists())
|
|
|
|
return luaL_error(L, "Lua include not found: %s", fnames.utf8_str().data());
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2007-01-15 23:19:50 +01:00
|
|
|
LuaScriptReader script_reader(fname.GetFullPath());
|
2011-09-28 21:48:37 +02:00
|
|
|
if (lua_load(L, script_reader.reader_func, &script_reader, fname.GetFullName().utf8_str()))
|
|
|
|
return luaL_error(L, "Error loading Lua include \"%s\":\n\n%s", fname.GetFullPath().utf8_str().data(), lua_tostring(L, -1));
|
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
int pretop = lua_gettop(L) - 1; // don't count the function value itself
|
|
|
|
lua_call(L, 0, LUA_MULTRET);
|
|
|
|
return lua_gettop(L) - pretop;
|
|
|
|
}
|
|
|
|
|
2007-02-15 13:56:36 +01:00
|
|
|
int LuaScript::LuaFrameFromMs(lua_State *L)
|
|
|
|
{
|
2011-09-28 21:48:37 +02:00
|
|
|
int ms = lua_tointeger(L, -1);
|
2007-02-15 13:56:36 +01:00
|
|
|
lua_pop(L, 1);
|
2011-09-28 21:48:37 +02:00
|
|
|
if (VideoContext::Get()->TimecodesLoaded())
|
2010-07-08 06:29:04 +02:00
|
|
|
lua_pushnumber(L, VideoContext::Get()->FrameAtTime(ms, agi::vfr::START));
|
2011-09-28 21:48:37 +02:00
|
|
|
else
|
2007-02-15 13:56:36 +01:00
|
|
|
lua_pushnil(L);
|
|
|
|
|
2011-09-28 21:48:37 +02:00
|
|
|
return 1;
|
|
|
|
}
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2007-02-15 13:56:36 +01:00
|
|
|
int LuaScript::LuaMsFromFrame(lua_State *L)
|
|
|
|
{
|
2011-09-28 21:48:37 +02:00
|
|
|
int frame = lua_tointeger(L, -1);
|
2007-02-15 13:56:36 +01:00
|
|
|
lua_pop(L, 1);
|
2011-09-28 21:48:37 +02:00
|
|
|
if (VideoContext::Get()->TimecodesLoaded())
|
2010-07-08 06:29:04 +02:00
|
|
|
lua_pushnumber(L, VideoContext::Get()->TimeAtFrame(frame, agi::vfr::START));
|
2011-09-28 21:48:37 +02:00
|
|
|
else
|
2007-02-15 13:56:36 +01:00
|
|
|
lua_pushnil(L);
|
|
|
|
|
2011-09-28 21:48:37 +02:00
|
|
|
return 1;
|
|
|
|
}
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2008-09-10 18:53:23 +02:00
|
|
|
int LuaScript::LuaVideoSize(lua_State *L)
|
|
|
|
{
|
|
|
|
VideoContext *ctx = VideoContext::Get();
|
|
|
|
if (ctx->IsLoaded()) {
|
|
|
|
lua_pushnumber(L, ctx->GetWidth());
|
|
|
|
lua_pushnumber(L, ctx->GetHeight());
|
|
|
|
lua_pushnumber(L, ctx->GetAspectRatioValue());
|
|
|
|
lua_pushnumber(L, ctx->GetAspectRatioType());
|
|
|
|
return 4;
|
|
|
|
} else {
|
|
|
|
lua_pushnil(L);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:47:40 +02:00
|
|
|
static void lua_threaded_call(ProgressSink *ps, lua_State *L, int nargs, int nresults, bool can_open_config)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
2011-09-28 21:47:40 +02:00
|
|
|
LuaProgressSink lps(L, ps, can_open_config);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:40 +02:00
|
|
|
if (lua_pcall(L, nargs, nresults, 0)) {
|
2011-09-28 21:48:37 +02:00
|
|
|
// if the call failed, log the error here
|
2011-09-28 21:47:40 +02:00
|
|
|
ps->Log("\n\nLua reported a runtime error:\n");
|
|
|
|
ps->Log(lua_tostring(L, -1));
|
2011-09-28 21:48:37 +02:00
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
2007-02-20 03:50:40 +01:00
|
|
|
|
2011-09-28 21:47:40 +02:00
|
|
|
lua_gc(L, LUA_GCCOLLECT, 0);
|
2011-09-28 21:48:37 +02:00
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:40 +02:00
|
|
|
|
|
|
|
// LuaThreadedCall
|
|
|
|
void LuaThreadedCall(lua_State *L, int nargs, int nresults, wxString const& title, wxWindow *parent, bool can_open_config)
|
|
|
|
{
|
|
|
|
BackgroundScriptRunner bsr(parent, title);
|
|
|
|
try {
|
|
|
|
bsr.Run(bind(lua_threaded_call, std::tr1::placeholders::_1, L, nargs, nresults, can_open_config));
|
|
|
|
}
|
|
|
|
catch (agi::UserCancelException const&) {
|
|
|
|
/// @todo perhaps this needs to continue up for exporting?
|
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// LuaFeature
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief DOCME
|
|
|
|
/// @param _L
|
|
|
|
/// @param _featureclass
|
|
|
|
/// @param _name
|
|
|
|
///
|
2006-12-28 22:18:35 +01:00
|
|
|
LuaFeature::LuaFeature(lua_State *_L, ScriptFeatureClass _featureclass, const wxString &_name)
|
|
|
|
: Feature(_featureclass, _name)
|
|
|
|
, L(_L)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief DOCME
|
|
|
|
///
|
2006-12-28 22:18:35 +01:00
|
|
|
void LuaFeature::RegisterFeature()
|
|
|
|
{
|
|
|
|
// get the LuaScript objects
|
|
|
|
lua_getfield(L, LUA_REGISTRYINDEX, "aegisub");
|
|
|
|
LuaScript *s = (LuaScript*)lua_touserdata(L, -1);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
|
|
|
|
// add the Feature object
|
2011-09-28 21:48:37 +02:00
|
|
|
myid = s->RegisterFeature(this);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
|
|
|
// create table with the functions
|
|
|
|
// get features table
|
|
|
|
lua_getfield(L, LUA_REGISTRYINDEX, "features");
|
|
|
|
lua_pushvalue(L, -2);
|
|
|
|
lua_rawseti(L, -2, myid);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief DOCME
|
|
|
|
/// @param functionid
|
|
|
|
///
|
2006-12-28 22:18:35 +01:00
|
|
|
void LuaFeature::GetFeatureFunction(int functionid)
|
|
|
|
{
|
|
|
|
// get feature table
|
|
|
|
lua_getfield(L, LUA_REGISTRYINDEX, "features");
|
|
|
|
// get this feature's function pointers
|
|
|
|
lua_rawgeti(L, -1, myid);
|
|
|
|
// get pointer for validation function
|
|
|
|
lua_rawgeti(L, -1, functionid);
|
|
|
|
lua_remove(L, -2);
|
|
|
|
lua_remove(L, -2);
|
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief DOCME
|
|
|
|
/// @param ints
|
|
|
|
///
|
2007-01-03 22:18:19 +01:00
|
|
|
void LuaFeature::CreateIntegerArray(const std::vector<int> &ints)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
|
|
|
// create an array-style table with an integer vector in it
|
|
|
|
// leave the new table on top of the stack
|
|
|
|
lua_newtable(L);
|
2007-01-24 04:54:32 +01:00
|
|
|
for (size_t i = 0; i != ints.size(); ++i) {
|
2010-06-30 01:14:46 +02:00
|
|
|
// We use zero-based indexing but Lua wants one-based, so add one
|
|
|
|
lua_pushinteger(L, ints[i] + 1);
|
2007-05-03 19:57:21 +02:00
|
|
|
lua_rawseti(L, -2, (int)i+1);
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief DOCME
|
|
|
|
///
|
2006-12-28 22:18:35 +01:00
|
|
|
void LuaFeature::ThrowError()
|
|
|
|
{
|
|
|
|
wxString err(lua_tostring(L, -1), wxConvUTF8);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
wxLogError(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// LuaFeatureMacro
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief DOCME
|
|
|
|
/// @param L
|
|
|
|
/// @return
|
|
|
|
///
|
2006-12-28 22:18:35 +01:00
|
|
|
int LuaFeatureMacro::LuaRegister(lua_State *L)
|
|
|
|
{
|
|
|
|
wxString _name(lua_tostring(L, 1), wxConvUTF8);
|
|
|
|
wxString _description(lua_tostring(L, 2), wxConvUTF8);
|
|
|
|
|
2007-01-03 05:31:17 +01:00
|
|
|
LuaFeatureMacro *macro = new LuaFeatureMacro(_name, _description, L);
|
2007-01-24 04:54:32 +01:00
|
|
|
(void)macro;
|
2006-12-28 22:18:35 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief DOCME
|
|
|
|
/// @param _name
|
|
|
|
/// @param _description
|
|
|
|
/// @param _L
|
|
|
|
///
|
2007-01-03 05:31:17 +01:00
|
|
|
LuaFeatureMacro::LuaFeatureMacro(const wxString &_name, const wxString &_description, lua_State *_L)
|
2007-01-15 16:27:13 +01:00
|
|
|
: Feature(SCRIPTFEATURE_MACRO, _name)
|
2007-01-03 05:31:17 +01:00
|
|
|
, FeatureMacro(_name, _description)
|
2007-01-15 16:27:13 +01:00
|
|
|
, LuaFeature(_L, SCRIPTFEATURE_MACRO, _name)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
|
|
|
// new table for containing the functions for this feature
|
|
|
|
lua_newtable(L);
|
|
|
|
// store processing function
|
2007-01-03 05:31:17 +01:00
|
|
|
if (!lua_isfunction(L, 3)) {
|
2006-12-28 22:18:35 +01:00
|
|
|
lua_pushstring(L, "The macro processing function must be a function");
|
|
|
|
lua_error(L);
|
|
|
|
}
|
2007-01-03 05:31:17 +01:00
|
|
|
lua_pushvalue(L, 3);
|
2006-12-28 22:18:35 +01:00
|
|
|
lua_rawseti(L, -2, 1);
|
|
|
|
// and validation function
|
2007-01-03 05:31:17 +01:00
|
|
|
lua_pushvalue(L, 4);
|
2006-12-28 22:18:35 +01:00
|
|
|
no_validate = !lua_isfunction(L, -1);
|
|
|
|
lua_rawseti(L, -2, 2);
|
|
|
|
// make the feature known
|
|
|
|
RegisterFeature();
|
|
|
|
// and remove the feature function table again
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief DOCME
|
|
|
|
/// @param subs
|
|
|
|
/// @param selected
|
|
|
|
/// @param active
|
|
|
|
/// @return
|
|
|
|
///
|
2007-01-03 22:18:19 +01:00
|
|
|
bool LuaFeatureMacro::Validate(AssFile *subs, const std::vector<int> &selected, int active)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
|
|
|
if (no_validate)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
GetFeatureFunction(2); // 2 = validation function
|
|
|
|
|
|
|
|
// prepare function call
|
|
|
|
LuaAssFile *subsobj = new LuaAssFile(L, subs, false, false);
|
2007-01-24 04:54:32 +01:00
|
|
|
(void) subsobj;
|
2006-12-28 22:18:35 +01:00
|
|
|
CreateIntegerArray(selected); // selected items
|
|
|
|
lua_pushinteger(L, -1); // active line
|
|
|
|
|
|
|
|
// do call
|
2009-07-23 01:07:46 +02:00
|
|
|
int err = lua_pcall(L, 3, 1, 0);
|
|
|
|
bool result;
|
|
|
|
if (err) {
|
|
|
|
wxString errmsg(lua_tostring(L, -1), wxConvUTF8);
|
2011-09-28 21:43:48 +02:00
|
|
|
wxLogWarning("Runtime error in Lua macro validation function:\n%s", errmsg);
|
2009-07-23 01:07:46 +02:00
|
|
|
result = false;
|
|
|
|
} else {
|
|
|
|
result = !!lua_toboolean(L, -1);
|
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2009-07-23 01:07:46 +02:00
|
|
|
// clean up stack (result or error message)
|
2006-12-28 22:18:35 +01:00
|
|
|
lua_pop(L, 1);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief DOCME
|
|
|
|
/// @param subs
|
|
|
|
/// @param selected
|
|
|
|
/// @param active
|
|
|
|
/// @param progress_parent
|
|
|
|
/// @return
|
|
|
|
///
|
2007-07-06 16:26:04 +02:00
|
|
|
void LuaFeatureMacro::Process(AssFile *subs, std::vector<int> &selected, int active, wxWindow * const progress_parent)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
|
|
|
GetFeatureFunction(1); // 1 = processing function
|
|
|
|
LuaAssFile *subsobj = new LuaAssFile(L, subs, true, true);
|
|
|
|
CreateIntegerArray(selected); // selected items
|
|
|
|
lua_pushinteger(L, -1); // active line
|
|
|
|
|
|
|
|
// do call
|
2007-07-06 16:26:04 +02:00
|
|
|
// 3 args: subtitles, selected lines, active line
|
|
|
|
// 1 result: new selected lines
|
2011-09-28 21:47:40 +02:00
|
|
|
LuaThreadedCall(L, 3, 1, GetName(), progress_parent, true);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:40 +02:00
|
|
|
subsobj->ProcessingComplete(GetName());
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2007-07-06 16:26:04 +02:00
|
|
|
// top of stack will be selected lines array, if any was returned
|
|
|
|
if (lua_istable(L, -1)) {
|
|
|
|
selected.clear();
|
|
|
|
selected.reserve(lua_objlen(L, -1));
|
|
|
|
lua_pushnil(L);
|
|
|
|
while (lua_next(L, -2)) {
|
|
|
|
if (lua_isnumber(L, -1)) {
|
2010-06-30 01:14:46 +02:00
|
|
|
// Lua uses one-based indexing but we want zero-based, so subtract one
|
|
|
|
selected.push_back(lua_tointeger(L, -1) - 1);
|
2007-07-06 16:26:04 +02:00
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
std::sort(selected.begin(), selected.end());
|
|
|
|
}
|
|
|
|
// either way, there will be something on the stack
|
|
|
|
lua_pop(L, 1);
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// LuaFeatureFilter
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief DOCME
|
|
|
|
/// @param _name
|
|
|
|
/// @param _description
|
|
|
|
/// @param merit
|
|
|
|
/// @param _L
|
|
|
|
///
|
2006-12-28 22:18:35 +01:00
|
|
|
LuaFeatureFilter::LuaFeatureFilter(const wxString &_name, const wxString &_description, int merit, lua_State *_L)
|
2007-01-15 16:27:13 +01:00
|
|
|
: Feature(SCRIPTFEATURE_FILTER, _name)
|
2006-12-28 22:18:35 +01:00
|
|
|
, FeatureFilter(_name, _description, merit)
|
2007-01-15 16:27:13 +01:00
|
|
|
, LuaFeature(_L, SCRIPTFEATURE_FILTER, _name)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
|
|
|
// Works the same as in LuaFeatureMacro
|
|
|
|
lua_newtable(L);
|
|
|
|
if (!lua_isfunction(L, 4)) {
|
|
|
|
lua_pushstring(L, "The filter processing function must be a function");
|
|
|
|
lua_error(L);
|
|
|
|
}
|
|
|
|
lua_pushvalue(L, 4);
|
|
|
|
lua_rawseti(L, -2, 1);
|
|
|
|
lua_pushvalue(L, 5);
|
|
|
|
has_config = lua_isfunction(L, -1);
|
|
|
|
lua_rawseti(L, -2, 2);
|
|
|
|
RegisterFeature();
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief DOCME
|
|
|
|
///
|
2006-12-28 22:18:35 +01:00
|
|
|
void LuaFeatureFilter::Init()
|
|
|
|
{
|
|
|
|
// Don't think there's anything to do here... (empty in auto3)
|
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief DOCME
|
|
|
|
/// @param L
|
|
|
|
/// @return
|
|
|
|
///
|
2006-12-28 22:18:35 +01:00
|
|
|
int LuaFeatureFilter::LuaRegister(lua_State *L)
|
|
|
|
{
|
|
|
|
wxString _name(lua_tostring(L, 1), wxConvUTF8);
|
|
|
|
wxString _description(lua_tostring(L, 2), wxConvUTF8);
|
|
|
|
int _merit = lua_tointeger(L, 3);
|
|
|
|
|
|
|
|
LuaFeatureFilter *filter = new LuaFeatureFilter(_name, _description, _merit, L);
|
2007-01-24 04:54:32 +01:00
|
|
|
(void) filter;
|
2006-12-28 22:18:35 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief DOCME
|
|
|
|
/// @param subs
|
|
|
|
/// @param export_dialog
|
|
|
|
///
|
2006-12-28 22:18:35 +01:00
|
|
|
void LuaFeatureFilter::ProcessSubs(AssFile *subs, wxWindow *export_dialog)
|
|
|
|
{
|
2008-01-24 00:02:26 +01:00
|
|
|
LuaStackcheck stackcheck(L);
|
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
GetFeatureFunction(1); // 1 = processing function
|
2007-02-20 03:50:40 +01:00
|
|
|
assert(lua_isfunction(L, -1));
|
2008-03-09 22:09:51 +01:00
|
|
|
stackcheck.check_stack(1);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
|
|
|
// prepare function call
|
|
|
|
// subtitles (undo doesn't make sense in exported subs, in fact it'll totally break the undo system)
|
|
|
|
LuaAssFile *subsobj = new LuaAssFile(L, subs, true/*allow modifications*/, false/*disallow undo*/);
|
2008-01-24 00:02:26 +01:00
|
|
|
assert(lua_isuserdata(L, -1));
|
2008-03-09 22:09:51 +01:00
|
|
|
stackcheck.check_stack(2);
|
2006-12-28 22:18:35 +01:00
|
|
|
// config
|
|
|
|
if (has_config && config_dialog) {
|
2008-01-24 00:02:26 +01:00
|
|
|
int results_produced = config_dialog->LuaReadBack(L);
|
|
|
|
assert(results_produced == 1);
|
2008-03-13 20:12:55 +01:00
|
|
|
(void) results_produced; // avoid warning on release builds
|
2006-12-28 22:18:35 +01:00
|
|
|
// TODO, write back stored options here
|
2007-02-20 03:50:40 +01:00
|
|
|
} else {
|
|
|
|
// no config so put an empty table instead
|
|
|
|
lua_newtable(L);
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
2008-01-24 00:02:26 +01:00
|
|
|
assert(lua_istable(L, -1));
|
2008-03-09 22:09:51 +01:00
|
|
|
stackcheck.check_stack(3);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:40 +02:00
|
|
|
LuaThreadedCall(L, 2, 0, AssExportFilter::GetName(), export_dialog, false);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2008-03-09 22:09:51 +01:00
|
|
|
stackcheck.check_stack(0);
|
2008-01-24 00:02:26 +01:00
|
|
|
|
2011-09-28 21:47:40 +02:00
|
|
|
subsobj->ProcessingComplete();
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief DOCME
|
|
|
|
/// @param parent
|
|
|
|
/// @return
|
|
|
|
///
|
2006-12-28 22:18:35 +01:00
|
|
|
ScriptConfigDialog* LuaFeatureFilter::GenerateConfigDialog(wxWindow *parent)
|
|
|
|
{
|
|
|
|
if (!has_config)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
GetFeatureFunction(2); // 2 = config dialog function
|
|
|
|
|
|
|
|
// prepare function call
|
|
|
|
// subtitles (don't allow any modifications during dialog creation, ideally the subs aren't even accessed)
|
|
|
|
LuaAssFile *subsobj = new LuaAssFile(L, AssFile::top, false/*allow modifications*/, false/*disallow undo*/);
|
2007-01-24 04:54:32 +01:00
|
|
|
(void) subsobj;
|
2006-12-28 22:18:35 +01:00
|
|
|
// stored options
|
|
|
|
lua_newtable(L); // TODO, nothing for now
|
|
|
|
|
|
|
|
// do call
|
2009-07-28 17:39:52 +02:00
|
|
|
int err = lua_pcall(L, 2, 1, 0);
|
|
|
|
if (err) {
|
|
|
|
wxString errmsg(lua_tostring(L, -1), wxConvUTF8);
|
2011-09-28 21:43:48 +02:00
|
|
|
wxLogWarning("Runtime error in Lua macro validation function:\n%s", errmsg);
|
2009-07-28 17:39:52 +02:00
|
|
|
lua_pop(L, 1); // remove error message
|
2007-02-20 03:50:40 +01:00
|
|
|
return config_dialog = 0;
|
2009-07-28 17:39:52 +02:00
|
|
|
} else {
|
|
|
|
// Create config dialogue from table on top of stack
|
|
|
|
return config_dialog = new LuaConfigDialog(L, false);
|
2007-02-20 03:50:40 +01:00
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
2011-09-28 21:46:05 +02:00
|
|
|
LuaScriptFactory::LuaScriptFactory()
|
|
|
|
: ScriptFactory("Lua", "*.lua")
|
2008-03-09 22:49:46 +01:00
|
|
|
{
|
|
|
|
Register(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Script* LuaScriptFactory::Produce(const wxString &filename) const
|
|
|
|
{
|
|
|
|
// Just check if file extension is .lua
|
|
|
|
// Reject anything else
|
2011-09-28 21:43:11 +02:00
|
|
|
if (filename.Right(4).Lower() == ".lua") {
|
2008-03-09 22:49:46 +01:00
|
|
|
return new LuaScript(filename);
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
};
|
2007-12-31 07:46:22 +01:00
|
|
|
|
2008-03-05 00:17:07 +01:00
|
|
|
#endif // WITH_AUTO4_LUA
|