Skip to content

Commit

Permalink
Wrap Spans (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksqsf authored Aug 19, 2024
1 parent 7be6974 commit 8953d7b
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion src/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1991,6 +1991,49 @@ namespace MemoryReg {
};
} // namespace MemoryReg

//--- wrappers for Spans
namespace SpansReg {
using T = Spans;

T make() {
return Spans();
}

size_t count(T& spans) {
return spans.Count();
}

size_t count_between(T& spans, size_t start, size_t end) {
return spans.Count(start, end);
}

static const luaL_Reg funcs[] = {
{ "Spans", WRAP(make) },
{ NULL, NULL },
};

static const luaL_Reg methods[] = {
{ "add_span", WRAPMEM(T, AddSpan) },
{ "add_spans", WRAPMEM(T, AddSpans) },
{ "previous_stop", WRAPMEM(T, PreviousStop) },
{ "next_stop", WRAPMEM(T, NextStop) },
{ "has_vertex", WRAPMEM(T, HasVertex) },
{ "count_between", WRAP(count_between) },
{ NULL, NULL },
};

static const luaL_Reg vars_get[] = {
{ "start", WRAPMEM(T, start) },
{ "end", WRAPMEM(T, end) },
{ "count", WRAP(count) },
{ NULL, NULL },
};

static const luaL_Reg vars_set[] = {
{ NULL, NULL },
};
} // namespace SpansReg

//--- wrappers for Phrase
namespace PhraseReg {
using T = Phrase;
Expand Down Expand Up @@ -2019,6 +2062,7 @@ namespace PhraseReg {

static const luaL_Reg methods[] = {
{ "toCandidate", WRAP(toCandidate)},
{ "spans", WRAPMEM(T, spans) },
{ NULL, NULL },
};

Expand All @@ -2036,7 +2080,6 @@ namespace PhraseReg {
{ "weight", WRAPMEM(T, weight)},
{ "code", WRAPMEM(T, code)},
{ "entry", WRAPMEM(T, entry)},
//span
//language doesn't wrap yet, so Wrap it later
{ NULL, NULL },
};
Expand Down Expand Up @@ -2299,6 +2342,7 @@ void types_init(lua_State *L) {
EXPORT(DictEntryReg, L);
EXPORT(CodeReg, L);
EXPORT(CommitEntryReg, L);
EXPORT(SpansReg, L);
EXPORT(PhraseReg, L);
EXPORT(SentenceReg, L);
EXPORT(KeySequenceReg, L);
Expand Down

0 comments on commit 8953d7b

Please sign in to comment.