all repos — mgba @ 732ed5fa4d91c339a3591529ba9e88d03659919b

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
 7
 8from collections import namedtuple
 9
10def createCallback(structName, cbName, funcName=None):
11    funcName = funcName or "_py{}{}".format(structName, cbName[0].upper() + cbName[1:])
12    fullStruct = "struct {}*".format(structName)
13    def cb(handle, *args):
14        h = ffi.cast(fullStruct, handle)
15        return getattr(ffi.from_handle(h.pyobj), cbName)(*args)
16
17    return ffi.def_extern(name=funcName)(cb)
18
19version = ffi.string(lib.projectVersion).decode('utf-8')
20
21GitInfo = namedtuple("GitInfo", "commit commitShort branch revision")
22
23git = {}
24if lib.gitCommit and lib.gitCommit != "(unknown)":
25    git['commit'] = ffi.string(lib.gitCommit).decode('utf-8')
26if lib.gitCommitShort and lib.gitCommitShort != "(unknown)":
27    git['commitShort'] = ffi.string(lib.gitCommitShort).decode('utf-8')
28if lib.gitBranch and lib.gitBranch != "(unknown)":
29    git['branch'] = ffi.string(lib.gitBranch).decode('utf-8')
30if lib.gitRevision > 0:
31    git['revision'] = lib.gitRevision
32
33git = GitInfo(**git)