\input luaotfload.sty

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% usage for glyph tests
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\baselineskip=17.28pt

\font\iwonaregular=name:iwona at 14.4pt
\font\lmromanten=file:lmroman10-regular.otf at 14.4pt
\font\cmuregular=file:cmunrm.otf at 14.4pt

%% wrap tests in macros (could move to style file)
\def\doifglyphelse#1#2#3{%
  \directlua{
    local codepoint = tonumber('\string#1')
    if not codepoint then codepoint = unicode.utf8.byte('\string#1') end
    if luaotfload.aux.font_has_glyph(font.current(), codepoint) then
      tex.sprint('\string#2')
    else
      tex.sprint('\string#3')
    end
  }%
}

\def\doifglyph#1#2{\doifglyphelse{#1}{#2}{}}

%% no otf font loaded yet, so both fail:
first:
\doifglyphelse{a}{true}{false}
\doifglyph    {a}{yep}

%% load lm and try repeat:
\lmromanten
second:
\doifglyphelse{a}{true}{false}
\doifglyph    {a}{yep}

%% let’s test some more free fonts
\def\checkglyphset{%
  \doifglyphelse  ö{ö}{nope}
  \doifglyphelse  п{п}{nope}
  \doifglyphelse  α{α}{nope}
  \doifglyphelse  Æ{Æ}{nope}
  \doifglyphelse  ą{ą}{nope}
  \doifglyphelse  ř{ř}{nope}
  \doifglyphelse  ˝{˝}{nope}
  \doifglyphelse  ѩ{ѩ}{nope}
  \endgraf
}

\iwonaregular \checkglyphset
\lmromanten   \checkglyphset
\cmuregular   \checkglyphset

\bye
