mirror of https://github.com/mgba-emu/mgba.git
Python: Reduce boilerplate
This commit is contained in:
parent
06d89aee48
commit
7b66a702cf
|
@ -0,0 +1,15 @@
|
|||
# Copyright (c) 2013-2017 Jeffrey Pfau
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
from ._pylib import ffi, lib
|
||||
|
||||
def createCallback(structName, cbName, funcName=None):
|
||||
funcName = funcName or "_py{}{}".format(structName, cbName.capitalize())
|
||||
fullStruct = "struct {}*".format(structName)
|
||||
def cb(handle, *args):
|
||||
h = ffi.cast(fullStruct, handle)
|
||||
getattr(ffi.from_handle(h.pyobj), cbName)(*args)
|
||||
|
||||
return ffi.def_extern(name=funcName)(cb)
|
|
@ -4,11 +4,9 @@
|
|||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
from ._pylib import ffi, lib
|
||||
from . import createCallback
|
||||
|
||||
@ffi.def_extern()
|
||||
def _pyLog(logger, category, level, message):
|
||||
l = ffi.cast("struct mLoggerPy*", logger)
|
||||
ffi.from_handle(l.pyobj).log(category, level, ffi.string(message).decode('UTF-8'))
|
||||
createCallback("mLoggerPy", "log", "_pyLog")
|
||||
|
||||
def installDefault(logger):
|
||||
lib.mLogSetDefaultLogger(logger._native)
|
||||
|
|
Loading…
Reference in New Issue