mirror of
https://github.com/H-uru/korman.git
synced 2025-07-14 02:27:36 -04:00
Implement Korlib API versioning
A common error when developing with Korman and Korlib is to forget to recompile _korlib on changes in the upstream C++ code. This will prevent the errors from being catastrophic and will revert the user to the python reference implementation with a minimum of fuss.
This commit is contained in:
@ -18,6 +18,9 @@
|
|||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
|
|
||||||
|
// This konstant is compared against that in the Python module to prevent sneaky errors...
|
||||||
|
#define KORLIB_API_VERSION 1
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
static PyMethodDef korlib_Methods[] = {
|
static PyMethodDef korlib_Methods[] = {
|
||||||
@ -46,6 +49,9 @@ PyMODINIT_FUNC PyInit__korlib() {
|
|||||||
// Module classes...
|
// Module classes...
|
||||||
PyModule_AddObject(module, "GLTexture", Init_pyGLTexture_Type());
|
PyModule_AddObject(module, "GLTexture", Init_pyGLTexture_Type());
|
||||||
|
|
||||||
|
// Konstants
|
||||||
|
PyModule_AddIntConstant(module, "_KORLIB_API_VERSION", KORLIB_API_VERSION);
|
||||||
|
|
||||||
return module;
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,11 +13,22 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with Korman. If not, see <http://www.gnu.org/licenses/>.
|
# along with Korman. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
_KORLIB_API_VERSION = 1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from _korlib import *
|
from _korlib import _KORLIB_API_VERSION as _C_API_VERSION
|
||||||
except ImportError:
|
if _KORLIB_API_VERSION != _C_API_VERSION:
|
||||||
|
raise ImportError()
|
||||||
|
|
||||||
|
except ImportError as ex:
|
||||||
from .texture import *
|
from .texture import *
|
||||||
|
|
||||||
|
if "_C_API_VERSION" in locals():
|
||||||
|
msg = "Korlib C Module Version mismatch (expected {}, got {}).".format(_KORLIB_API_VERSION, _C_API_VERSION)
|
||||||
|
else:
|
||||||
|
msg = "Korlib C Module did not load correctly."
|
||||||
|
print(msg, "Using PyKorlib :(", sep=' ')
|
||||||
|
|
||||||
def create_bump_LUT(mipmap):
|
def create_bump_LUT(mipmap):
|
||||||
kLUTHeight = 16
|
kLUTHeight = 16
|
||||||
kLUTWidth = 16
|
kLUTWidth = 16
|
||||||
@ -57,11 +68,9 @@ except ImportError:
|
|||||||
def inspect_voribsfile(stream, header):
|
def inspect_voribsfile(stream, header):
|
||||||
raise NotImplementedError("Ogg Vorbis not supported unless _korlib is compiled")
|
raise NotImplementedError("Ogg Vorbis not supported unless _korlib is compiled")
|
||||||
|
|
||||||
def is_c_library():
|
|
||||||
return False
|
|
||||||
else:
|
else:
|
||||||
def is_c_library():
|
from _korlib import *
|
||||||
return True
|
|
||||||
finally:
|
finally:
|
||||||
from .console import ConsoleToggler
|
from .console import ConsoleToggler
|
||||||
from .texture import TEX_DETAIL_ALPHA, TEX_DETAIL_ADD, TEX_DETAIL_MULTIPLY
|
from .texture import TEX_DETAIL_ALPHA, TEX_DETAIL_ADD, TEX_DETAIL_MULTIPLY
|
||||||
|
Reference in New Issue
Block a user