Commit 0ed3ff31 authored by Jonathan Michalon's avatar Jonathan Michalon

Libs: remove hacks: basic type workaround and header name adjustment

Basic type struct inheritanace seems broken but:
- one was never used (PlayerID)
- the other (TileID) works almost the same without being a registered GType.
We lose the ability to make a true property with it but accessors are still
available to C users.
About header name, it just has to be defined once for the namespace as CCode
tag and that's enough, no need to sed around anymore.
By the way the definition of DATADIR which was stealing a hack.vapi slot
goes to a new file called -config and is declared as extern there which is
sufficient to be overridden by a -D at C compile time.
parent 63240b2b
......@@ -3,7 +3,7 @@ VALADOC_MODULE_NAME = LibOVCC
VALADOC_SRCDIR = $(top_srcdir)/src
VALADOC_FILES = $(wildcard $(VALADOC_SRCDIR)/*.vala) \
$(wildcard $(VALADOC_SRCDIR)/*/*.vala)
VALADOC_FLAGS = $(LIBOVCC_VALAFLAGS) --pkg=hack
VALADOC_FLAGS = $(LIBOVCC_VALAFLAGS)
VALADOC_LIB = $(top_builddir)/src/.libs/libovcc.so
VALADOC_CHEADER = $(VALADOC_SRCDIR)/ovcc.h
......
......@@ -2,16 +2,15 @@ lib_LTLIBRARIES = libovcc.la
noinst_PROGRAMS = test
EXTRA_DIST = hack.h hack.vapi \
ovcc.h ovcc.vapi
EXTRA_DIST = ovcc.h ovcc.vapi
libovcc_la_CPPFLAGS = -DG_LOG_DOMAIN=\"LibOVCC\"
libovcc_la_CFLAGS = $(LIBOVCC_CFLAGS) \
-DDATADIR='"$(pkgdatadir)"'
-DOVCC_CONFIG_DATADIR='"$(pkgdatadir)"'
libovcc_la_LIBADD = $(LIBOVCC_LIBS)
libovcc_la_VALAFLAGS = $(LIBOVCC_VALAFLAGS) --library=ovcc --header=ovcc.h \
--vapidir=. --pkg=hack
libovcc_la_VALAFLAGS = $(LIBOVCC_VALAFLAGS) --library=ovcc --header=ovcc.h
libovcc_la_SOURCES = ovcc-board.vala \
ovcc-config.vala \
ovcc-game.vala \
ovcc-pawn.vala \
ovcc-player.vala \
......@@ -43,19 +42,3 @@ test_SOURCES = test.c
test.c: ovcc.h
$(srcdir)/ovcc.h $(srcdir)/ovcc.vapi: libovcc_la_vala.stamp
$(lib_LTLIBRARIES): stamp-hack
# FIXME: how to force re-generation of ovcc.h and ovcc.vapi if they got removed?
stamp-hack: ovcc.h ovcc.vapi
(f=`mktemp $@.XXXXXXXXXX`; trap -- "rm -f '$$f'" EXIT QUIT TERM; \
ovcc_h=ovcc.h; [ -f "$$ovcc_h" ] || ovcc_h="$(srcdir)/$$ovcc_h"; \
cat $(srcdir)/hack.h "$$ovcc_h" | $(SED) '/<hack.h>/d'> "$$f" && \
(echo "/* this file is auto-generated, do not modify it (XXX: generated by valac) */" && \
cat "$$f") > ovcc.h)
(f=`mktemp $@.XXXXXXXXXX`; trap -- "rm -f '$$f'" EXIT QUIT TERM; \
ovcc_vapi=ovcc.vapi; [ -f "$$ovcc_vapi" ] || ovcc_vapi="$(srcdir)/$$ovcc_vapi"; \
cat $(srcdir)/hack.vapi "$$ovcc_vapi" | $(SED) 's~"\(hack\|ovcc\).h"~"ovcc/ovcc.h"~g' > "$$f" && \
(echo "/* this file is auto-generated, do not modify it (XXX: generated by valac) */" && \
cat "$$f") > ovcc.vapi)
touch $@
/*
*
* Copyright (C) 2011 Colomban Wendling <ban@herbesfolles.org>
* Jonathan Michalon <studios.chalmion@no-log.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
[CCode (cheader_filename = "hack.h")]
namespace OVCC
{
[CCode (cprefix = "", lower_case_cprefix = "")]
namespace Config {
public const string DATADIR;
}
[SimpleType]
[CCode (type_id = "G_TYPE_UINT",
marshaller_type_name = "UINT",
get_value_function = "g_value_get_uint",
set_value_function = "g_value_set_uint",
default_value = "0U",
type_signature = "u")]
[IntegerType (rank = 7)]
public struct PlayerID : uint
{
}
[SimpleType]
[CCode (type_id = "G_TYPE_UINT",
marshaller_type_name = "UINT",
get_value_function = "g_value_get_uint",
set_value_function = "g_value_set_uint",
default_value = "0U",
type_signature = "u")]
[IntegerType (rank = 7)]
public struct TileID : uint
{
public new string to_string ()
{
return "t%u".printf (this);
}
public static TileID from_string (string str)
throws GLib.ConvertError
{
if (! str.has_prefix ("t")) {
throw new GLib.ConvertError.ILLEGAL_SEQUENCE (""""%s" is not a valid tile ID""", str);
}
return (TileID)Utils.string_to_uint ((string)((char *)str + 1));
}
}
}
/*
*
* Copyright (C) 2011 Colomban Wendling <ban@herbesfolles.org>
* Copyright (C) 2019 Colomban Wendling <ban@herbesfolles.org>
* Jonathan Michalon <studios.chalmion@no-log.org>
*
* This program is free software: you can redistribute it and/or modify
......@@ -18,32 +18,15 @@
*
*/
/*
* This file contains definitions of types derived from basic types, such as
* integers. This is needed because Vala seems to fuck this up (as of
* valac 0.11.5) and make a type half-boxed half-simple.
*
* See also hack.vapi that contains the VAPI for this file, and anything that
* can land in it (such as type methods).
*/
#ifndef OVCC_HACK_H
#define OVCC_HACK_H
#include <glib.h>
G_BEGIN_DECLS
typedef guint OVCCPlayerID;
typedef guint OVCCTileID;
#define OVCC_TYPE_PLAYER_ID G_TYPE_UINT
#define OVCC_TYPE_TILE_ID G_TYPE_UINT
#define ovcc_player_id_get_type() OVCC_TYPE_PLAYER_ID
#define ovcc_tile_id_get_type() OVCC_TYPE_TILE_ID
G_END_DECLS
/* configure the .h location for the whole namespace */
[CCode (cheader_filename = "ovcc/ovcc.h")]
namespace OVCC
{
}
#endif /* guard */
namespace OVCC.Config
{
/* variable is fed by -DDATADIR= at C compile time */
extern const string DATADIR;
}
......@@ -30,7 +30,6 @@ namespace OVCC
private List<Pawn> _pawns = new List<Pawn> ();
private uint[] remaining_pawns = new uint[PawnKind.N_KINDS];
public PlayerID id { get; private set; }
public uint score { get; set; }
[Description (nick = "Nick", blurb = "Player's nickname")]
public string nick { get; construct;}
......
......@@ -24,6 +24,26 @@ namespace OVCC
{
INVALID_TILE_ID
}
[CCode (has_type_id = false)]
[IntegerType (rank = 7)]
public struct TileID : uint
{
public new string to_string ()
{
return "t%u".printf (this);
}
public static TileID from_string (string str)
throws GLib.ConvertError
{
if (! str.has_prefix ("t")) {
throw new GLib.ConvertError.ILLEGAL_SEQUENCE (""""%s" is not a valid tile ID""", str);
}
return (TileID)Utils.string_to_uint ((string)((char *)str + 1));
}
}
/**
* Represents a tile
......@@ -36,7 +56,7 @@ namespace OVCC
private SList<TileObject> _objects;
/* properties */
public TileID id { get; construct; }
public TileID id { get; private set; }
public SList<TileObject> objects {
get {
return this._objects;
......@@ -69,7 +89,8 @@ namespace OVCC
public Tile (TileID id,
SList<TileObject> objects)
{
Object (id: id, objects: objects);
Object (objects: objects);
this.id = id;
}
public Tile dup ()
......
......@@ -11,12 +11,4 @@ libovccclient_la_SOURCES = ovccclient-client.vala \
ovccclientinclude_HEADERS = ovccclient.h
vapi_DATA = ovccclient.vapi
$(lib_LTLIBRARIES): stamp-hack
$(srcdir)/ovccclient.h $(srcdir)/ovccclient.vapi: libovccclient_la_vala.stamp
# hack: add prefix to header filename in VAPI file
stamp-hack: $(srcdir)/ovccclient.vapi
$(AM_V_GEN) \
$(SED) -i 's~"\(ovccclient.h\)"~"ovcc/\1"~g' $<
touch $@
......@@ -20,7 +20,7 @@
using OVCC;
[CCode (cprefix = "OVCCClient", lower_case_cprefix = "ovccclient_")]
[CCode (cprefix = "OVCCClient", lower_case_cprefix = "ovccclient_", cheader_filename = "ovcc/ovccclient.h")]
namespace OVCCClient
{
/**
......
......@@ -38,7 +38,7 @@
using OVCC;
using OVCC.Network;
[CCode (cprefix = "OVCCClient", lower_case_cprefix = "ovccclient_")]
[CCode (cprefix = "OVCCClient", lower_case_cprefix = "ovccclient_", cheader_filename = "ovcc/ovccclient.h")]
namespace OVCCClient
{
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment