all repos — mgba @ 9edbe75ff8c2741b1e7a9c54718f849227d7941b

mGBA Game Boy Advance Emulator

src/platform/python/mgba/__init__.py (view raw)

 1# Copyright (c) 2013-2017 Jeffrey Pfau
 2#
 3# This Source Code Form is subject to the terms of the Mozilla Public
 4# License, v. 2.0. If a copy of the MPL was not distributed with this
 5# file, You can obtain one at http://mozilla.org/MPL/2.0/.
 6from ._pylib import ffi, lib  # pylint: disable=no-name-in-module
 7
 8
 9class Git:
10    commit = None
11    if lib.gitCommit and lib.gitCommit != "(unknown)":
12        commit = ffi.string(lib.gitCommit).decode('utf-8')
13
14    commitShort = None
15    if lib.gitCommitShort and lib.gitCommitShort != "(unknown)":
16        commitShort = ffi.string(lib.gitCommitShort).decode('utf-8')
17
18    branch = None
19    if lib.gitBranch and lib.gitBranch != "(unknown)":
20        branch = ffi.string(lib.gitBranch).decode('utf-8')
21
22    revision = None
23    if lib.gitRevision > 0:
24        revision = lib.gitRevision
25
26
27def create_callback(struct_name, cb_name, func_name=None):
28    func_name = func_name or "_py{}{}".format(struct_name, cb_name[0].upper() + cb_name[1:])
29    full_struct = "struct {}*".format(struct_name)
30
31    def callback(handle, *args):
32        handle = ffi.cast(full_struct, handle)
33        return getattr(ffi.from_handle(handle.pyobj), cb_name)(*args)
34
35    return ffi.def_extern(name=func_name)(callback)
36
37
38__version__ = ffi.string(lib.projectVersion).decode('utf-8')