about summary refs log tree commit diff stats
path: root/014literal_noninteger.cc
blob: 5f0b0327f25c9d48b60e1b30aca82d711a4dbbef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//: Support literal non-integers.
//: '3.14159:literal' is ugly, so we'll just say '3.14159' for non-integers.

:(scenarios load)
:(scenario noninteger_literal)
recipe main [
  1:number <- copy 3.14159
]
+parse:   ingredient: {name: "3.14159", properties: ["3.14159": "literal-number"]}

:(after "reagent::reagent(string s)")
  if (is_noninteger(s)) {
    name = s;
    types.push_back(0);
    properties.push_back(pair<string, vector<string> >(name, vector<string>()));
    properties.back().second.push_back("literal-number");
    set_value(to_double(s));
    return;
  }

:(code)
bool is_noninteger(const string& s) {
  return s.find_first_not_of("0123456789-.") == string::npos
      && s.find('.') != string::npos;
}

double to_double(string n) {
  char* end = NULL;
  // safe because string.c_str() is guaranteed to be null-terminated
  double result = strtod(n.c_str(), &end);
  assert(*end == '\0');
  return result;
}
-----------------------*/ LUASOCKET_API int luaopen_socket_unix(lua_State *L) { int i; lua_newtable(L); int socket_unix_table = lua_gettop(L); for (i = 0; mod[i].name; i++) mod[i].func(L); /* Add backwards compatibility aliases "tcp" and "udp" for the "stream" and * "dgram" functions. */ add_alias(L, socket_unix_table, "tcp", "stream"); add_alias(L, socket_unix_table, "udp", "dgram"); /* Add a backwards compatibility function and a metatable setup to call it * for the old socket.unix() interface. */ lua_pushcfunction(L, compat_socket_unix_call); lua_setfield(L, socket_unix_table, "__call"); lua_pushvalue(L, socket_unix_table); lua_setmetatable(L, socket_unix_table); return 1; }