2006-12-28 22:18:35 +01:00
|
|
|
// Copyright (c) 2006, Niels Martin Hansen
|
|
|
|
// 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_assfile.cpp
|
|
|
|
/// @brief Lua 5.1-based scripting engine (interface to subtitle files)
|
|
|
|
/// @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
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#ifndef AGI_PRE
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <wx/log.h>
|
|
|
|
#endif
|
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
#include <libaegisub/exception.h>
|
2010-06-09 01:21:39 +02:00
|
|
|
#include <libaegisub/log.h>
|
2011-09-28 21:46:23 +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"
|
2011-09-28 21:46:23 +02:00
|
|
|
#include "ass_karaoke.h"
|
2006-12-28 22:18:35 +01:00
|
|
|
#include "ass_override.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "ass_style.h"
|
|
|
|
#include "auto4_lua.h"
|
2009-06-25 00:22:45 +02:00
|
|
|
#include "utils.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:47:03 +02:00
|
|
|
namespace {
|
|
|
|
void set_field(lua_State *L, const char *name, wxString const& value)
|
|
|
|
{
|
|
|
|
lua_pushstring(L, value.utf8_str());
|
|
|
|
lua_setfield(L, -2, name);
|
|
|
|
}
|
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
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
void set_field(lua_State *L, const char *name, const char *value)
|
|
|
|
{
|
|
|
|
lua_pushstring(L, value);
|
|
|
|
lua_setfield(L, -2, name);
|
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
// Userdata object must be just above the target table
|
|
|
|
void set_field(lua_State *L, const char *name, lua_CFunction value)
|
|
|
|
{
|
|
|
|
assert(lua_type(L, -2) == LUA_TUSERDATA);
|
|
|
|
lua_pushvalue(L, -2);
|
|
|
|
lua_pushcclosure(L, value, 1);
|
|
|
|
lua_setfield(L, -2, name);
|
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
void set_field(lua_State *L, const char *name, bool value)
|
|
|
|
{
|
|
|
|
lua_pushboolean(L, value);
|
|
|
|
lua_setfield(L, -2, name);
|
|
|
|
}
|
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
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
void set_field(lua_State *L, const char *name, double value)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
2011-09-28 21:47:03 +02:00
|
|
|
lua_pushnumber(L, value);
|
|
|
|
lua_setfield(L, -2, name);
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
void set_field(lua_State *L, const char *name, int value)
|
|
|
|
{
|
|
|
|
lua_pushinteger(L, value);
|
|
|
|
lua_setfield(L, -2, name);
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:47:40 +02:00
|
|
|
DEFINE_SIMPLE_EXCEPTION_NOINNER(BadField, agi::Exception, "automation/macro/bad_field")
|
2011-09-28 21:47:03 +02:00
|
|
|
BadField bad_field(const char *expected_type, const char *name, const char *line_clasee)
|
|
|
|
{
|
|
|
|
return BadField(std::string("Invalid ") + expected_type + " '" + name + "' field in '" + line_clasee + "' class subtitle line");
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString get_string_field(lua_State *L, const char *name, const char *line_class)
|
|
|
|
{
|
|
|
|
lua_getfield(L, -1, name);
|
|
|
|
if (!lua_isstring(L, -1))
|
|
|
|
throw bad_field("string", name, line_class);
|
|
|
|
wxString ret(lua_tostring(L, -1), wxConvUTF8);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
double get_double_field(lua_State *L, const char *name, const char *line_class)
|
|
|
|
{
|
|
|
|
lua_getfield(L, -1, name);
|
|
|
|
if (!lua_isnumber(L, -1))
|
|
|
|
throw bad_field("number", name, line_class);
|
|
|
|
double ret = lua_tonumber(L, -1);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_int_field(lua_State *L, const char *name, const char *line_class)
|
|
|
|
{
|
|
|
|
lua_getfield(L, -1, name);
|
|
|
|
if (!lua_isnumber(L, -1))
|
|
|
|
throw bad_field("number", name, line_class);
|
|
|
|
int ret = lua_tointeger(L, -1);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool get_bool_field(lua_State *L, const char *name, const char *line_class)
|
|
|
|
{
|
|
|
|
lua_getfield(L, -1, name);
|
|
|
|
if (!lua_isboolean(L, -1))
|
|
|
|
throw bad_field("boolean", name, line_class);
|
|
|
|
bool ret = !!lua_toboolean(L, -1);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
using namespace Automation4;
|
|
|
|
template<int (LuaAssFile::*closure)(lua_State *)>
|
|
|
|
int closure_wrapper(lua_State *L)
|
|
|
|
{
|
|
|
|
return (LuaAssFile::GetObjPointer(L, lua_upvalueindex(1))->*closure)(L);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<void (LuaAssFile::*closure)(lua_State *)>
|
|
|
|
int closure_wrapper_v(lua_State *L)
|
|
|
|
{
|
|
|
|
(LuaAssFile::GetObjPointer(L, lua_upvalueindex(1))->*closure)(L);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:47:12 +02:00
|
|
|
int modification_mask(AssEntry *e)
|
|
|
|
{
|
|
|
|
switch (e->GetType())
|
|
|
|
{
|
|
|
|
case ENTRY_DIALOGUE: return AssFile::COMMIT_DIAG_ADDREM;
|
|
|
|
case ENTRY_STYLE: return AssFile::COMMIT_STYLES;
|
|
|
|
case ENTRY_ATTACHMENT: return AssFile::COMMIT_ATTACHMENT;
|
|
|
|
default: return AssFile::COMMIT_SCRIPTINFO;
|
2011-09-28 21:47:03 +02:00
|
|
|
}
|
2011-09-28 21:47:12 +02:00
|
|
|
}
|
|
|
|
}
|
2011-09-28 21:47:03 +02:00
|
|
|
|
|
|
|
namespace Automation4 {
|
|
|
|
void LuaAssFile::CheckAllowModify()
|
|
|
|
{
|
|
|
|
if (!can_modify)
|
|
|
|
luaL_error(L, "Attempt to modify subtitles in read-only feature context.");
|
|
|
|
}
|
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 LuaAssFile::AssEntryToLua(lua_State *L, AssEntry *e)
|
|
|
|
{
|
|
|
|
lua_newtable(L);
|
|
|
|
|
|
|
|
wxString raw(e->GetEntryData());
|
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
set_field(L, "section", e->group);
|
|
|
|
set_field(L, "raw", raw);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
if (StringEmptyOrWhitespace(raw)) {
|
|
|
|
set_field(L, "class", "clear");
|
|
|
|
}
|
|
|
|
else if (raw[0] == ';') {
|
2006-12-28 22:18:35 +01:00
|
|
|
// "text" field, same as "raw" but with semicolon stripped
|
2011-09-28 21:47:03 +02:00
|
|
|
set_field(L, "text", raw.Mid(1));
|
|
|
|
set_field(L, "class", "comment");
|
|
|
|
}
|
|
|
|
else if (raw[0] == '[') {
|
|
|
|
set_field(L, "class", "head");
|
|
|
|
}
|
|
|
|
else if (e->group.Lower() == "[script info]") {
|
|
|
|
set_field(L, "key", raw.BeforeFirst(':'));
|
|
|
|
set_field(L, "value", raw.AfterFirst(':'));
|
|
|
|
set_field(L, "class", "info");
|
|
|
|
}
|
|
|
|
else if (raw.Left(7).Lower() == "format:") {
|
|
|
|
// TODO: parse the format line; just use a tokenizer
|
|
|
|
set_field(L, "class", "format");
|
|
|
|
}
|
|
|
|
else if (AssDialogue *dia = dynamic_cast<AssDialogue*>(e)) {
|
|
|
|
set_field(L, "comment", dia->Comment);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
set_field(L, "layer", dia->Layer);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
set_field(L, "start_time", dia->Start.GetMS());
|
|
|
|
set_field(L, "end_time", dia->End.GetMS());
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
set_field(L, "style", dia->Style);
|
|
|
|
set_field(L, "actor", dia->Actor);
|
|
|
|
set_field(L, "effect", dia->Effect);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
set_field(L, "margin_l", dia->Margin[0]);
|
|
|
|
set_field(L, "margin_r", dia->Margin[1]);
|
|
|
|
set_field(L, "margin_t", dia->Margin[2]);
|
|
|
|
set_field(L, "margin_b", dia->Margin[3]);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
set_field(L, "text", dia->Text);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
set_field(L, "class", "dialogue");
|
|
|
|
}
|
|
|
|
else if (AssStyle *sty = dynamic_cast<AssStyle*>(e)) {
|
|
|
|
set_field(L, "name", sty->name);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
set_field(L, "fontname", sty->font);
|
|
|
|
set_field(L, "fontsize", sty->fontsize);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
set_field(L, "color1", sty->primary.GetASSFormatted(true));
|
|
|
|
set_field(L, "color2", sty->secondary.GetASSFormatted(true));
|
|
|
|
set_field(L, "color3", sty->outline.GetASSFormatted(true));
|
|
|
|
set_field(L, "color4", sty->shadow.GetASSFormatted(true));
|
|
|
|
|
|
|
|
set_field(L, "bold", sty->bold);
|
|
|
|
set_field(L, "italic", sty->italic);
|
|
|
|
set_field(L, "underline", sty->underline);
|
|
|
|
set_field(L, "strikeout", sty->strikeout);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
set_field(L, "scale_x", sty->scalex);
|
|
|
|
set_field(L, "scale_y", sty->scaley);
|
|
|
|
|
|
|
|
set_field(L, "spacing", sty->spacing);
|
|
|
|
|
|
|
|
set_field(L, "angle", sty->angle);
|
|
|
|
|
|
|
|
set_field(L, "borderstyle", sty->borderstyle);
|
|
|
|
set_field(L, "outline", sty->outline_w);
|
|
|
|
set_field(L, "shadow", sty->shadow_w);
|
|
|
|
|
|
|
|
set_field(L, "align", sty->alignment);
|
|
|
|
|
|
|
|
set_field(L, "margin_l", sty->Margin[0]);
|
|
|
|
set_field(L, "margin_r", sty->Margin[1]);
|
|
|
|
set_field(L, "margin_t", sty->Margin[2]);
|
|
|
|
set_field(L, "margin_b", sty->Margin[3]);
|
|
|
|
|
|
|
|
set_field(L, "encoding", sty->encoding);
|
|
|
|
|
|
|
|
set_field(L, "relative_to", 2);// From STS.h: "0: window, 1: video, 2: undefined (~window)"
|
|
|
|
|
|
|
|
set_field(L, "class", "style");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
set_field(L, "class", "unknown");
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AssEntry *LuaAssFile::LuaToAssEntry(lua_State *L)
|
|
|
|
{
|
|
|
|
// assume an assentry table is on the top of the stack
|
|
|
|
// convert it to a real AssEntry object, and pop the table from the stack
|
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
if (!lua_istable(L, -1))
|
|
|
|
luaL_error(L, "Can't convert a non-table value to AssEntry");
|
2006-12-28 22:18:35 +01:00
|
|
|
|
|
|
|
lua_getfield(L, -1, "class");
|
2011-09-28 21:47:03 +02:00
|
|
|
if (!lua_isstring(L, -1))
|
|
|
|
luaL_error(L, "Table lacks 'class' field, can't convert to AssEntry");
|
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
wxString lclass(lua_tostring(L, -1), wxConvUTF8);
|
|
|
|
lclass.MakeLower();
|
|
|
|
lua_pop(L, 1);
|
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
AssEntry *result = 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
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
try {
|
|
|
|
wxString section = get_string_field(L, "section", "common");
|
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
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
if (lclass == "clear")
|
|
|
|
result = new AssEntry("");
|
|
|
|
else if (lclass == "comment")
|
|
|
|
result = new AssEntry(";" + get_string_field(L, "text", "comment"));
|
|
|
|
else if (lclass == "head")
|
|
|
|
result = new AssEntry(section);
|
|
|
|
else if (lclass == "info") {
|
|
|
|
result = new AssEntry(wxString::Format("%s: %s", get_string_field(L, "key", "info"), get_string_field(L, "value", "info")));
|
|
|
|
result->group = "[Script Info]"; // just so it can be read correctly back
|
|
|
|
}
|
|
|
|
else if (lclass == "format") {
|
|
|
|
// ohshi- ...
|
|
|
|
// *FIXME* maybe ignore the actual data and just put some default stuff based on section?
|
|
|
|
result = new AssEntry("Format: Auto4,Is,Broken");
|
|
|
|
}
|
|
|
|
else if (lclass == "style") {
|
|
|
|
AssStyle *sty = new AssStyle;
|
|
|
|
result = sty;
|
|
|
|
sty->name = get_string_field(L, "name", "style");
|
|
|
|
sty->font = get_string_field(L, "fontname", "style");
|
|
|
|
sty->fontsize = get_double_field(L, "fontsize", "style");
|
|
|
|
sty->primary.Parse(get_string_field(L, "color1", "style"));
|
|
|
|
sty->secondary.Parse(get_string_field(L, "color2", "style"));
|
|
|
|
sty->outline.Parse(get_string_field(L, "color3", "style"));
|
|
|
|
sty->shadow.Parse(get_string_field(L, "color4", "style"));
|
|
|
|
sty->bold = get_bool_field(L, "bold", "style");
|
|
|
|
sty->italic = get_bool_field(L, "italic", "style");
|
|
|
|
sty->underline = get_bool_field(L, "underline", "style");
|
|
|
|
sty->strikeout = get_bool_field(L, "strikeout", "style");
|
|
|
|
sty->scalex = get_double_field(L, "scale_x", "style");
|
|
|
|
sty->scaley = get_double_field(L, "scale_y", "style");
|
|
|
|
sty->spacing = get_double_field(L, "spacing", "style");
|
|
|
|
sty->angle = get_double_field(L, "angle", "style");
|
|
|
|
sty->borderstyle = get_int_field(L, "borderstyle", "style");
|
|
|
|
sty->outline_w = get_double_field(L, "outline", "style");
|
|
|
|
sty->shadow_w = get_double_field(L, "shadow", "style");
|
|
|
|
sty->alignment = get_int_field(L, "align", "style");
|
|
|
|
sty->Margin[0] = get_int_field(L, "margin_l", "style");
|
|
|
|
sty->Margin[1] = get_int_field(L, "margin_r", "style");
|
|
|
|
sty->Margin[2] = get_int_field(L, "margin_t", "style");
|
|
|
|
sty->Margin[3] = get_int_field(L, "margin_b", "style");
|
|
|
|
sty->encoding = get_int_field(L, "encoding", "style");
|
|
|
|
sty->UpdateData();
|
|
|
|
}
|
|
|
|
else if (lclass == "dialogue") {
|
|
|
|
AssDialogue *dia = new AssDialogue;
|
|
|
|
result = dia;
|
|
|
|
|
|
|
|
dia->Comment = get_bool_field(L, "comment", "dialogue");
|
|
|
|
dia->Layer = get_int_field(L, "layer", "dialogue");
|
|
|
|
dia->Start.SetMS(get_int_field(L, "start_time", "dialogue"));
|
|
|
|
dia->End.SetMS(get_int_field(L, "end_time", "dialogue"));
|
|
|
|
dia->Style = get_string_field(L, "style", "dialogue");
|
|
|
|
dia->Actor = get_string_field(L, "actor", "dialogue");
|
|
|
|
dia->Margin[0] = get_int_field(L, "margin_l", "dialogue");
|
|
|
|
dia->Margin[1] = get_int_field(L, "margin_r", "dialogue");
|
|
|
|
dia->Margin[2] = get_int_field(L, "margin_t", "dialogue");
|
|
|
|
dia->Margin[3] = get_int_field(L, "margin_b", "dialogue");
|
|
|
|
dia->Effect = get_string_field(L, "effect", "dialogue");
|
|
|
|
dia->Text = get_string_field(L, "text", "dialogue");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
luaL_error(L, "Found line with unknown class: %s", lclass.utf8_str().data());
|
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
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
if (result->group.empty())
|
|
|
|
result->group = section;
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
catch (agi::Exception const& e) {
|
|
|
|
delete result;
|
|
|
|
luaL_error(L, e.GetMessage().c_str());
|
|
|
|
return 0;
|
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
void LuaAssFile::SeekCursorTo(int n)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
2011-09-28 21:47:12 +02:00
|
|
|
if (n <= 0 || n > (int)ass->Line.size())
|
|
|
|
luaL_error(L, "Requested out-of-range line from subtitle file: %d", n);
|
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
if (n < last_entry_id - n) {
|
2006-12-28 22:18:35 +01:00
|
|
|
// fastest to search from start
|
2011-09-28 21:47:03 +02:00
|
|
|
last_entry_ptr = ass->Line.begin();
|
|
|
|
last_entry_id = 1;
|
|
|
|
}
|
|
|
|
else if ((int)ass->Line.size() - last_entry_id < abs(last_entry_id - n)) {
|
2006-12-28 22:18:35 +01:00
|
|
|
// fastest to search from end
|
2011-09-28 21:47:03 +02:00
|
|
|
last_entry_ptr = ass->Line.end();
|
|
|
|
last_entry_id = ass->Line.size() + 1;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
2011-09-28 21:47:03 +02:00
|
|
|
// otherwise fastest to search from cursor
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
advance(last_entry_ptr, n - last_entry_id);
|
|
|
|
last_entry_id = n;
|
|
|
|
}
|
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 LuaAssFile::ObjectIndexRead(lua_State *L)
|
|
|
|
{
|
|
|
|
switch (lua_type(L, 2)) {
|
|
|
|
case LUA_TNUMBER:
|
2011-09-28 21:47:03 +02:00
|
|
|
// read an indexed AssEntry
|
2011-09-28 21:47:12 +02:00
|
|
|
SeekCursorTo(lua_tointeger(L, 2));
|
2011-09-28 21:47:03 +02:00
|
|
|
AssEntryToLua(L, *last_entry_ptr);
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case LUA_TSTRING:
|
|
|
|
{
|
|
|
|
// either return n or a function doing further stuff
|
|
|
|
const char *idx = lua_tostring(L, 2);
|
|
|
|
|
|
|
|
if (strcmp(idx, "n") == 0) {
|
|
|
|
// get number of items
|
|
|
|
lua_pushnumber(L, ass->Line.size());
|
2006-12-28 22:18:35 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
lua_pushvalue(L, 1);
|
|
|
|
if (strcmp(idx, "delete") == 0)
|
|
|
|
lua_pushcclosure(L, closure_wrapper_v<&LuaAssFile::ObjectDelete>, 1);
|
|
|
|
else if (strcmp(idx, "deleterange") == 0)
|
|
|
|
lua_pushcclosure(L, closure_wrapper_v<&LuaAssFile::ObjectDeleteRange>, 1);
|
|
|
|
else if (strcmp(idx, "insert") == 0)
|
|
|
|
lua_pushcclosure(L, closure_wrapper_v<&LuaAssFile::ObjectInsert>, 1);
|
|
|
|
else if (strcmp(idx, "append") == 0)
|
|
|
|
lua_pushcclosure(L, closure_wrapper_v<&LuaAssFile::ObjectAppend>, 1);
|
|
|
|
else {
|
|
|
|
// idiot
|
|
|
|
lua_pop(L, 1);
|
|
|
|
return luaL_error(L, "Invalid indexing in Subtitle File object: '%s'", idx);
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
default:
|
2011-09-28 21:47:03 +02:00
|
|
|
// crap, user is stupid!
|
|
|
|
return luaL_error(L, "Attempt to index a Subtitle File object with value of type '%s'.", lua_typename(L, lua_type(L, 2)));
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(false);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
void LuaAssFile::ObjectIndexWrite(lua_State *L)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
|
|
|
// instead of implementing everything twice, just call the other modification-functions from here
|
|
|
|
// after modifying the stack to match their expectations
|
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
CheckAllowModify();
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
int n = luaL_checkint(L, 2);
|
2006-12-28 22:18:35 +01:00
|
|
|
if (n < 0) {
|
|
|
|
// insert line so new index is n
|
2011-09-28 21:47:03 +02:00
|
|
|
lua_remove(L, 1);
|
2006-12-28 22:18:35 +01:00
|
|
|
lua_pushinteger(L, -n);
|
2011-09-28 21:47:03 +02:00
|
|
|
lua_replace(L, 1);
|
|
|
|
ObjectInsert(L);
|
|
|
|
}
|
|
|
|
else if (n == 0) {
|
2006-12-28 22:18:35 +01:00
|
|
|
// append line to list
|
2011-09-28 21:47:03 +02:00
|
|
|
lua_remove(L, 1);
|
|
|
|
lua_remove(L, 2);
|
|
|
|
ObjectAppend(L);
|
|
|
|
}
|
|
|
|
else {
|
2006-12-28 22:18:35 +01:00
|
|
|
// replace line at index n or delete
|
|
|
|
if (!lua_isnil(L, 3)) {
|
|
|
|
// insert
|
|
|
|
AssEntry *e = LuaToAssEntry(L);
|
2011-09-28 21:47:12 +02:00
|
|
|
modification_type |= modification_mask(e);
|
2011-09-28 21:47:03 +02:00
|
|
|
SeekCursorTo(n);
|
|
|
|
delete *last_entry_ptr;
|
|
|
|
*last_entry_ptr = e;
|
|
|
|
}
|
|
|
|
else {
|
2006-12-28 22:18:35 +01:00
|
|
|
// delete
|
2011-09-28 21:47:03 +02:00
|
|
|
lua_remove(L, 1);
|
|
|
|
lua_remove(L, 2);
|
|
|
|
ObjectDelete(L);
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int LuaAssFile::ObjectGetLen(lua_State *L)
|
|
|
|
{
|
2011-09-28 21:47:03 +02:00
|
|
|
lua_pushnumber(L, ass->Line.size());
|
2006-12-28 22:18:35 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
void LuaAssFile::ObjectDelete(lua_State *L)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
2011-09-28 21:47:03 +02:00
|
|
|
CheckAllowModify();
|
2011-09-28 21:46:23 +02:00
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
// get number of items to delete
|
|
|
|
int itemcount = lua_gettop(L);
|
|
|
|
std::vector<int> ids;
|
|
|
|
ids.reserve(itemcount);
|
|
|
|
|
|
|
|
while (itemcount > 0) {
|
2011-09-28 21:47:03 +02:00
|
|
|
int n = luaL_checkint(L, itemcount);
|
|
|
|
luaL_argcheck(L, n > 0 && n <= (int)ass->Line.size(), itemcount, "Out of range line index");
|
|
|
|
ids.push_back(n);
|
2006-12-28 22:18:35 +01:00
|
|
|
--itemcount;
|
|
|
|
}
|
2011-09-28 21:47:03 +02:00
|
|
|
|
|
|
|
// sort the item id's so we can delete from last to first to preserve original numbering
|
|
|
|
sort(ids.begin(), ids.end());
|
2006-12-28 22:18:35 +01:00
|
|
|
|
|
|
|
// now delete the id's backwards
|
2011-09-28 21:47:03 +02:00
|
|
|
SeekCursorTo(ids.back());
|
|
|
|
for (size_t i = ids.size(); i > 0; --i) {
|
|
|
|
while (last_entry_id > ids[i - 1]) {
|
|
|
|
--last_entry_ptr;
|
|
|
|
--last_entry_id;
|
|
|
|
}
|
2011-09-28 21:47:12 +02:00
|
|
|
modification_type |= modification_mask(*last_entry_ptr);
|
2011-09-28 21:47:03 +02:00
|
|
|
delete *last_entry_ptr;
|
|
|
|
ass->Line.erase(last_entry_ptr++);
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
void LuaAssFile::ObjectDeleteRange(lua_State *L)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
2011-09-28 21:47:03 +02:00
|
|
|
CheckAllowModify();
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
int a = std::max<int>(luaL_checkinteger(L, 1), 1);
|
|
|
|
int b = std::min<int>(luaL_checkinteger(L, 2), ass->Line.size());
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
SeekCursorTo(a);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
while (a++ <= b) {
|
2011-09-28 21:47:12 +02:00
|
|
|
modification_type |= modification_mask(*last_entry_ptr);
|
2011-09-28 21:47:03 +02:00
|
|
|
delete *last_entry_ptr;
|
|
|
|
ass->Line.erase(last_entry_ptr++);
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
void LuaAssFile::ObjectAppend(lua_State *L)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
2011-09-28 21:47:03 +02:00
|
|
|
CheckAllowModify();
|
2011-09-28 21:46:23 +02:00
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
int n = lua_gettop(L);
|
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
if (last_entry_ptr != ass->Line.begin()) {
|
|
|
|
last_entry_ptr--;
|
|
|
|
last_entry_id--;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 1; i <= n; i++) {
|
|
|
|
lua_pushvalue(L, i);
|
|
|
|
AssEntry *e = LuaToAssEntry(L);
|
2011-09-28 21:47:12 +02:00
|
|
|
modification_type |= modification_mask(*last_entry_ptr);
|
2010-06-24 22:48:49 +02:00
|
|
|
if (e->GetType() == ENTRY_DIALOGUE) {
|
|
|
|
// find insertion point, looking backwards
|
2011-09-28 21:47:03 +02:00
|
|
|
std::list<AssEntry*>::iterator it = ass->Line.end();
|
2010-06-24 22:48:49 +02:00
|
|
|
do { --it; } while ((*it)->GetType() != ENTRY_DIALOGUE);
|
|
|
|
// found last dialogue entry in file, move one past
|
|
|
|
++it;
|
2011-09-28 21:47:03 +02:00
|
|
|
ass->Line.insert(it, e);
|
2010-06-24 22:48:49 +02:00
|
|
|
}
|
|
|
|
else {
|
2011-09-28 21:47:03 +02:00
|
|
|
ass->Line.push_back(e);
|
2010-06-24 22:48:49 +02:00
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
void LuaAssFile::ObjectInsert(lua_State *L)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
2011-09-28 21:47:03 +02:00
|
|
|
CheckAllowModify();
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
int before = luaL_checkinteger(L, 1);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
// + 1 to allow appending at the end of the file
|
|
|
|
luaL_argcheck(L, before > 0 && before <= (int)ass->Line.size() + 1, 1,
|
|
|
|
"Out of range line index");
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
SeekCursorTo(before);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
int n = lua_gettop(L);
|
2006-12-28 22:18:35 +01:00
|
|
|
for (int i = 2; i <= n; i++) {
|
|
|
|
lua_pushvalue(L, i);
|
2011-09-28 21:47:12 +02:00
|
|
|
AssEntry *e = LuaToAssEntry(L);
|
|
|
|
modification_type |= modification_mask(e);
|
|
|
|
ass->Line.insert(last_entry_ptr, e);
|
2006-12-28 22:18:35 +01:00
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
last_entry_id += n - 1;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
void LuaAssFile::ObjectGarbageCollect(lua_State *L)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
2011-09-28 21:47:03 +02:00
|
|
|
references--;
|
|
|
|
if (!references) delete this;
|
2010-06-09 01:21:39 +02:00
|
|
|
LOG_D("automation/lua") << "Garbage collected LuaAssFile";
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int LuaAssFile::LuaParseTagData(lua_State *L)
|
|
|
|
{
|
|
|
|
lua_newtable(L);
|
|
|
|
// TODO
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int LuaAssFile::LuaUnparseTagData(lua_State *L)
|
|
|
|
{
|
|
|
|
lua_pushstring(L, "");
|
|
|
|
// TODO
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int LuaAssFile::LuaParseKaraokeData(lua_State *L)
|
|
|
|
{
|
2011-09-28 21:46:23 +02:00
|
|
|
agi::scoped_ptr<AssEntry> e(LuaToAssEntry(L));
|
|
|
|
AssDialogue *dia = dynamic_cast<AssDialogue*>(e.get());
|
2011-09-28 21:47:03 +02:00
|
|
|
luaL_argcheck(L, dia, 1, "Subtitle line must be a dialogue line");
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:46:23 +02:00
|
|
|
AssKaraoke kara(dia);
|
|
|
|
for (AssKaraoke::iterator it = kara.begin(); it != kara.end(); ++it) {
|
2011-09-28 21:47:03 +02:00
|
|
|
lua_newtable(L);
|
2011-09-28 21:46:23 +02:00
|
|
|
set_field(L, "duration", it->duration);
|
|
|
|
set_field(L, "start_time", it->start_time);
|
|
|
|
set_field(L, "end_time", it->start_time + it->duration);
|
|
|
|
set_field(L, "tag", it->tag_type);
|
|
|
|
set_field(L, "text", it->GetText(false));
|
|
|
|
set_field(L, "text_stripped", it->text);
|
|
|
|
lua_rawseti(L, -2, -1);
|
2011-09-28 21:47:03 +02:00
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
void LuaAssFile::LuaSetUndoPoint(lua_State *L)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
2011-09-28 21:47:03 +02:00
|
|
|
if (!can_set_undo)
|
|
|
|
luaL_error(L, "Attempt to set an undo point in a context where it makes no sense to do so.");
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:47:12 +02:00
|
|
|
if (modification_type) {
|
|
|
|
ass->Commit(wxString(luaL_checkstring(L, 1), wxConvUTF8), modification_type);
|
|
|
|
modification_type = 0;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LuaAssFile *LuaAssFile::GetObjPointer(lua_State *L, int idx)
|
|
|
|
{
|
|
|
|
assert(lua_type(L, idx) == LUA_TUSERDATA);
|
|
|
|
void *ud = lua_touserdata(L, idx);
|
|
|
|
return *((LuaAssFile**)ud);
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
void LuaAssFile::ProcessingComplete(wxString const& undo_description)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
2011-09-28 21:47:12 +02:00
|
|
|
if (modification_type && can_set_undo && !undo_description.empty()) {
|
|
|
|
ass->Commit(undo_description, modification_type);
|
|
|
|
modification_type = 0;
|
2011-09-28 21:47:03 +02:00
|
|
|
}
|
|
|
|
references--;
|
|
|
|
if (!references) delete this;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
LuaAssFile::LuaAssFile(lua_State *L, AssFile *ass, bool can_modify, bool can_set_undp)
|
|
|
|
: ass(ass)
|
|
|
|
, L(L)
|
|
|
|
, can_modify(can_modify)
|
|
|
|
, can_set_undo(can_set_undo)
|
2011-09-28 21:47:12 +02:00
|
|
|
, modification_type(0)
|
2011-09-28 21:47:03 +02:00
|
|
|
, references(2)
|
2011-09-28 21:47:12 +02:00
|
|
|
, last_entry_ptr(ass->Line.begin())
|
|
|
|
, last_entry_id(1)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
|
|
|
// prepare userdata object
|
2011-09-28 21:47:03 +02:00
|
|
|
*static_cast<LuaAssFile**>(lua_newuserdata(L, sizeof(LuaAssFile**))) = this;
|
2006-12-28 22:18:35 +01:00
|
|
|
|
|
|
|
// make the metatable
|
|
|
|
lua_newtable(L);
|
2011-09-28 21:47:03 +02:00
|
|
|
set_field(L, "__index", closure_wrapper<&LuaAssFile::ObjectIndexRead>);
|
|
|
|
set_field(L, "__newindex", closure_wrapper_v<&LuaAssFile::ObjectIndexWrite>);
|
|
|
|
set_field(L, "__len", closure_wrapper<&LuaAssFile::ObjectGetLen>);
|
|
|
|
set_field(L, "__gc", closure_wrapper_v<&LuaAssFile::ObjectGarbageCollect>);
|
2006-12-28 22:18:35 +01:00
|
|
|
lua_setmetatable(L, -2);
|
|
|
|
|
|
|
|
// register misc functions
|
|
|
|
// assume the "aegisub" global table exists
|
|
|
|
lua_getglobal(L, "aegisub");
|
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
set_field(L, "parse_tag_data", closure_wrapper<&LuaAssFile::LuaParseTagData>);
|
|
|
|
set_field(L, "unparse_tag_data", closure_wrapper<&LuaAssFile::LuaUnparseTagData>);
|
|
|
|
set_field(L, "parse_karaoke_data", closure_wrapper<&LuaAssFile::LuaParseKaraokeData>);
|
|
|
|
set_field(L, "set_undo_point", closure_wrapper_v<&LuaAssFile::LuaSetUndoPoint>);
|
2008-03-05 00:17:07 +01:00
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
lua_pop(L, 1); // pop "aegisub" table
|
2009-07-29 07:43:02 +02:00
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
// Leaves userdata object on stack
|
|
|
|
}
|
|
|
|
};
|
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
|
|
|
|
2011-09-28 21:47:03 +02:00
|
|
|
#endif // WITH_AUTO4_LUA
|