diff options
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/lua/llanglib.c')
-rw-r--r-- | Build/source/texk/web2c/luatexdir/lua/llanglib.c | 81 |
1 files changed, 59 insertions, 22 deletions
diff --git a/Build/source/texk/web2c/luatexdir/lua/llanglib.c b/Build/source/texk/web2c/luatexdir/lua/llanglib.c index 645780ca1c7..3356e734189 100644 --- a/Build/source/texk/web2c/luatexdir/lua/llanglib.c +++ b/Build/source/texk/web2c/luatexdir/lua/llanglib.c @@ -37,11 +37,10 @@ static int lang_new(lua_State * L) } else { int lualang; lang = lua_newuserdata(L, sizeof(struct tex_language *)); - lualang=(int)lua_tonumber(L, 1); + lualang = lua_tointeger(L, 1); *lang = get_language(lualang); if (!*lang) { - return luaL_error(L, "lang.new(%d): undefined language", - lua_tonumber(L, 1)); + return luaL_error(L, "lang.new(%d): undefined language", lualang); } } luaL_getmetatable(L, LANG_METATABLE); @@ -53,7 +52,7 @@ static int lang_id(lua_State * L) { struct tex_language **lang_ptr; lang_ptr = check_islang(L, 1); - lua_pushnumber(L, (*lang_ptr)->id); + lua_pushinteger(L, (*lang_ptr)->id); return 1; } @@ -92,8 +91,7 @@ static int lang_hyphenation(lua_State * L) lang_ptr = check_islang(L, 1); if (lua_gettop(L) != 1) { if (lua_type(L, 2) != LUA_TSTRING) { - return luaL_error(L, - "lang.hyphenation(): argument should be a string"); + return luaL_error(L, "lang.hyphenation(): argument should be a string"); } load_hyphenation(*lang_ptr, (const unsigned char *) lua_tostring(L, 2)); return 0; @@ -115,10 +113,10 @@ static int lang_pre_hyphen_char(lua_State * L) if (lua_type(L, 2) != LUA_TNUMBER) { return luaL_error(L, "lang.prehyphenchar(): argument should be a character number"); } - (*lang_ptr)->pre_hyphen_char=(int)lua_tonumber(L, 2); + (*lang_ptr)->pre_hyphen_char = (int) lua_tointeger(L, 2); return 0; } else { - lua_pushnumber(L, (*lang_ptr)->pre_hyphen_char); + lua_pushinteger(L, (*lang_ptr)->pre_hyphen_char); return 1; } } @@ -131,10 +129,10 @@ static int lang_post_hyphen_char(lua_State * L) if (lua_type(L, 2) != LUA_TNUMBER) { return luaL_error(L, "lang.posthyphenchar(): argument should be a character number"); } - (*lang_ptr)->post_hyphen_char=(int)lua_tonumber(L, 2); + (*lang_ptr)->post_hyphen_char = (int) lua_tointeger(L, 2); return 0; } else { - lua_pushnumber(L, (*lang_ptr)->post_hyphen_char); + lua_pushinteger(L, (*lang_ptr)->post_hyphen_char); return 1; } } @@ -148,14 +146,43 @@ static int lang_pre_exhyphen_char(lua_State * L) if (lua_type(L, 2) != LUA_TNUMBER) { return luaL_error(L, "lang.preexhyphenchar(): argument should be a character number"); } - (*lang_ptr)->pre_exhyphen_char=(int)lua_tonumber(L, 2); + (*lang_ptr)->pre_exhyphen_char = (int) lua_tointeger(L, 2); return 0; } else { - lua_pushnumber(L, (*lang_ptr)->pre_exhyphen_char); + lua_pushinteger(L, (*lang_ptr)->pre_exhyphen_char); return 1; } } +static int lang_sethjcode(lua_State * L) +{ + struct tex_language **lang_ptr; + lang_ptr = check_islang(L, 1); + if (lua_type(L, 2) != LUA_TNUMBER) { + return luaL_error(L, "lang.sethjcode(): argument should be a character number"); + } else { + int i = (int) lua_tointeger(L, 2) ; + if (lua_type(L, 3) == LUA_TNUMBER) { + set_hj_code((*lang_ptr)->id,i,(int) lua_tointeger(L, 3),-1); + } else { + set_hj_code((*lang_ptr)->id,i,i,-1); + } + } + return 0; +} + +static int lang_gethjcode(lua_State * L) +{ + struct tex_language **lang_ptr; + lang_ptr = check_islang(L, 1); + if (lua_type(L, 2) != LUA_TNUMBER) { + return luaL_error(L, "lang.gethjcode(): argument should be a character number"); + } else { + lua_pushinteger(L, get_hj_code((*lang_ptr)->id,lua_tointeger(L, 2))); + } + return 1; +} + static int lang_post_exhyphen_char(lua_State * L) { struct tex_language **lang_ptr; @@ -164,15 +191,14 @@ static int lang_post_exhyphen_char(lua_State * L) if (lua_type(L, 2) != LUA_TNUMBER) { return luaL_error(L, "lang.postexhyphenchar(): argument should be a character number"); } - (*lang_ptr)->post_exhyphen_char=(int)lua_tonumber(L, 2); + (*lang_ptr)->post_exhyphen_char = (int) lua_tointeger(L, 2); return 0; } else { - lua_pushnumber(L, (*lang_ptr)->post_exhyphen_char); + lua_pushinteger(L, (*lang_ptr)->post_exhyphen_char); return 1; } } - static int lang_hyphenation_min(lua_State * L) { struct tex_language **lang_ptr; @@ -181,10 +207,10 @@ static int lang_hyphenation_min(lua_State * L) if (lua_type(L, 2) != LUA_TNUMBER) { return luaL_error(L, "lang.hyphenationmin(): argument should be a number"); } - (*lang_ptr)->hyphenation_min=(int)lua_tonumber(L, 2); + (*lang_ptr)->hyphenation_min = (int) lua_tointeger(L, 2); return 0; } else { - lua_pushnumber(L, (*lang_ptr)->hyphenation_min); + lua_pushinteger(L, (*lang_ptr)->hyphenation_min); return 1; } } @@ -197,14 +223,22 @@ static int lang_clear_hyphenation(lua_State * L) return 0; } - static int do_lang_clean(lua_State * L) { char *cleaned; - if (lua_type(L, 1) != LUA_TSTRING) { - return luaL_error(L, "lang.clean(): argument should be a string"); + if (lua_type(L, 1) == LUA_TSTRING) { + (void) clean_hyphenation(int_par(cur_lang_code), lua_tostring(L, 1), &cleaned); + } else { + struct tex_language **lang_ptr; + lang_ptr = check_islang(L, 1); + if (lang_ptr == NULL) { + return luaL_error(L, "lang.clean(): first argument should be a string or language"); + } else if (lua_type(L, 2) != LUA_TSTRING) { + return luaL_error(L, "lang.clean(): second argument should be a string"); + } else { + (void) clean_hyphenation((*lang_ptr)->id,lua_tostring(L, 2), &cleaned); + } } - (void) clean_hyphenation(lua_tostring(L, 1), &cleaned); lua_pushstring(L, cleaned); return 1; } @@ -227,7 +261,6 @@ static int do_lang_hyphenate(lua_State * L) return 1; } - static const struct luaL_Reg langlib_d[] = { /* *INDENT-OFF* */ {"clear_patterns", lang_clear_patterns}, @@ -239,6 +272,8 @@ static const struct luaL_Reg langlib_d[] = { {"preexhyphenchar", lang_pre_exhyphen_char}, {"postexhyphenchar", lang_post_exhyphen_char}, {"hyphenationmin", lang_hyphenation_min}, + {"sethjcode", lang_sethjcode}, + {"gethjcode", lang_gethjcode}, {"id", lang_id}, /* *INDENT-ON* */ {NULL, NULL} /* sentinel */ @@ -256,6 +291,8 @@ static const struct luaL_Reg langlib[] = { {"preexhyphenchar", lang_pre_exhyphen_char}, {"postexhyphenchar", lang_post_exhyphen_char}, {"hyphenationmin", lang_hyphenation_min}, + {"sethjcode", lang_sethjcode}, + {"gethjcode", lang_gethjcode}, {"id", lang_id}, {"clean", do_lang_clean}, {"hyphenate", do_lang_hyphenate}, |