Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions automation/v4-docs/misc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,39 @@ Returns: 4 values, all numbers.

---

Getting the Aegisub version

aegisub.version (table)

A table describing the version of Aegisub the script is running in, with
these fields:

@string (string)
The full version string, e.g. "3.5.0" for a release or
"9900-master-4e440a614" for a development build. Use it for display and
logging only; its format may change.

@major, @minor, @patch (numbers)
The version numbers of the latest release this version of Aegisub was built
from (or of the release being prepared). A development build made after
3.5.0 reports 3.5.0, so it is safe to use these to check that the features
of a given release are available.

@build (number or nil)
The build number, which increases with every commit to Aegisub's main
branch. It can be used to check for features which were added after the
latest release, but is only meaningful for official builds: other branches
and forks may number their builds differently. nil if unknown.

Wherever possible, check for the specific feature you need instead, e.g.
"if aegisub.some_function then". The version is mainly useful for changes that
can't be detected that way, such as new optional arguments.

aegisub.version was added after 3.5.0; scripts that need to run in older
versions should check that it exists first.

---

Getting the audio waveform selection position and duration

function aegisub.get_audio_selection()
Expand Down
7 changes: 7 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ if get_option('debug') and host_machine.system() != 'windows'
endif

conf = configuration_data()
# The version declared above is that of the latest release this was built
# from, or of the release being prepared
aegisub_version = meson.project_version().split('.')
assert(aegisub_version.length() == 3, 'The project version must be of the form X.Y.Z')
conf.set('AEGISUB_VERSION_MAJOR', aegisub_version[0].to_int())
conf.set('AEGISUB_VERSION_MINOR', aegisub_version[1].to_int())
conf.set('AEGISUB_VERSION_PATCH', aegisub_version[2].to_int())
conf.set_quoted('P_DATA', dataroot)
conf.set_quoted('P_LOCALE', localedir)
if get_option('credit') != ''
Expand Down
19 changes: 18 additions & 1 deletion src/auto4_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "subs_controller.h"
#include "video_controller.h"
#include "utils.h"
#include "version.h"

#include <libaegisub/dispatch.h>
#include <libaegisub/lua/ffi.h>
Expand Down Expand Up @@ -115,6 +116,20 @@ namespace {
return 1;
}

/// Push the table for aegisub.version
void push_version(lua_State *L)
{
lua_createtable(L, 0, 5);
set_field(L, "string", GetVersionNumber());
auto numbers = GetVersionNumbers();
set_field(L, "major", numbers[0]);
set_field(L, "minor", numbers[1]);
set_field(L, "patch", numbers[2]);
// Unknown when built from a shallow clone
if (int build = GetSVNRevision())
set_field(L, "build", build);
}

int get_translation(lua_State *L)
{
wxString str(check_wxstring(L, 1));
Expand Down Expand Up @@ -504,7 +519,7 @@ namespace {

// make "aegisub" table
lua_pushstring(L, "aegisub");
lua_createtable(L, 0, 13);
lua_createtable(L, 0, 14);

set_field<LuaCommand::LuaRegister>(L, "register_macro");
set_field<LuaExportFilter::LuaRegister>(L, "register_filter");
Expand All @@ -516,6 +531,8 @@ namespace {
set_field<decode_path>(L, "decode_path");
set_field<cancel_script>(L, "cancel");
set_field(L, "lua_automation_version", 4);
push_version(L);
lua_setfield(L, -2, "version");
set_field<clipboard_init>(L, "__init_clipboard");
set_field<raise_warning_onload>(L, "__raise_warning");
set_field<get_file_name>(L, "file_name");
Expand Down
4 changes: 4 additions & 0 deletions src/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ bool GetIsOfficialRelease() {
#endif
}

std::array<int, 3> GetVersionNumbers() {
return {AEGISUB_VERSION_MAJOR, AEGISUB_VERSION_MINOR, AEGISUB_VERSION_PATCH};
}

const char *GetVersionNumber() {
return BUILD_GIT_VERSION_STRING;
}
Expand Down
5 changes: 5 additions & 0 deletions src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

#pragma once

#include <array>

/// Version string appended in title bar of main window (quick identification of all elements of a build)
const char *GetAegisubLongVersionString();
/// Version string used in About box, looks nicer
Expand All @@ -44,6 +46,9 @@ const char *GetAegisubBuildTime();
const char *GetAegisubBuildCredit();
/// Is release?
bool GetIsOfficialRelease();
/// The version numbers declared in meson.build: those of the latest release
/// this was built from, or of the release being prepared
std::array<int, 3> GetVersionNumbers();
/// Version number
const char *GetVersionNumber();
/// Get SVN revision
Expand Down
Loading