Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add TranslationReg methods transform for instance of LuaTranslation #224

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,21 @@ namespace TranslationReg {
lua_pushvalue(L, 1);
return 2;
}

// tran:transform(func,...) ==> tran.transform(tran,func, ...)
// --> Translation(func,tran,...) -- replace args and call Translation(args...)
// lua_call(L, n, 1); func(tran[,...])
int raw_transform(lua_State *L) {
int n = lua_gettop(L);
if ( 2 > n )
return 0;

lua_pushcfunction(L, raw_make); // tran,func,...,raw_make
lua_rotate(L, 2, -1); // tran, ... raw_make, func
lua_rotate(L, 1, 2); // raw_make, func, tarn,...
lua_call(L, n, 1);
return 1;
}

static const luaL_Reg funcs[] = {
{ "Translation", raw_make },
Expand All @@ -244,6 +259,7 @@ namespace TranslationReg {

static const luaL_Reg methods[] = {
{ "iter", raw_iter },
{ "transform", raw_transform },
{ NULL, NULL },
};

Expand Down