<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="Content-Style-Type" content="text/css" />
  <meta name="generator" content="pandoc" />
  <title></title>
  <style type="text/css">code{white-space: pre;}</style>
</head>
<body>
<p>Hi Pierre,</p>
<p>On 2016-11-28 05:22, Pierre wrote:</p>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<pre><code> See next comment regarding preprocessor evaluation rather than runtime
 checks.</code></pre>
</blockquote>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<pre><code> The above, and what follows, makes more sense as a preprocessor
 condition, given that `sizeof` will not change during runtime (and I
 fear unwanted compiler diagnostics related to "always true" vs "always
 false").</code></pre>
</blockquote>
<pre><code> It is not quite a runtime check: it is optimized away at compile time.</code></pre>
</blockquote>
<p>Yes, of course, but I was referring to the semantics of the check, not that the branch condition would actually evaluated.</p>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<pre><code> I would still prefer to do it in preprocessor, yes; but I don't know how
 to. I don't know how to access sizeof(val.i_int) from the preprocessor,
 and I don't know how to test sizeof(lua_Integer). I suppose it would be
 possible to add autoconf macros testing lua types, but that seems very
 heavy to me. Better ideas are welcome.</code></pre>
</blockquote>
<p>Using <code>sizeof</code> is not really what you want, you should compare the <em>max</em>/<em>min</em> value of the two types in order to properly check if the value will fit.</p>
<p>It is far too early in the morning, and I have as usual not slept for what seems like days and days.. but the below should reflect what you want.</p>
<pre><code>#if LUA_MININTEGER > INT64_MIN || LUA_MAXINTEGER < INT64_MAX
    if( val.i_int < LUA_MININTEGER || val.i_int > LUA_MAXINTEGER )
        lua_pushnumber( L, (lua_Number)val.i_int );
    else
#else
    lua_pushinteger( L, val.i_int );
#endif</code></pre>
<p>Given that we, <em>afaik</em>, do not have a <code>macro</code> related to the <em>max</em> and <em>min</em> of <code>vlc_value_t::i_int</code>, the above uses <code>INT64_MAX</code> and <code>INT64_MIN</code> (which is the valid range for the <em>data-member</em> in question) directly.</p>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<pre><code> `roundf` is in `<math.h>` starting with `C99`.</code></pre>
</blockquote>
<pre><code> Okay, yes.
 </code></pre>
</blockquote>
</body>
</html>