all repos — mgba @ aa8f77c18f33515af4b90b1dd9ab20c66846bf49

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
 8def createCallback(structName, cbName, funcName=None):
 9    funcName = funcName or "_py{}{}".format(structName, cbName[0].upper() + cbName[1:])
10    fullStruct = "struct {}*".format(structName)
11    def cb(handle, *args):
12        h = ffi.cast(fullStruct, handle)
13        return getattr(ffi.from_handle(h.pyobj), cbName)(*args)
14
15    return ffi.def_extern(name=funcName)(cb)