Пример #1
0
const char *luaG_openlibs( lua_State *L, const char *libs ) {
    const char *p;
    unsigned len;

	if (!libs) return NULL;     // no libs, not even 'base'

    // 'lua.c' stops GC during initialization so perhaps its a good idea. :)
    //
    lua_gc(L, LUA_GCSTOP, 0);

    // Anything causes 'base' to be taken in
    //
    STACK_GROW(L,2);
    lua_pushcfunction( L, luaopen_base );
    lua_pushliteral( L, "" );
    lua_call( L, 1, 0 );

    for( p= libs; *p; p+=len ) {
        len=0;
        while (*p && !is_name_char(*p)) p++;    // bypass delimiters
        while (is_name_char(p[len])) len++;     // bypass name
        if (len && (!openlib( L, p, len )))
            break;
    }
    lua_gc(L, LUA_GCRESTART, 0);

    return *p ? p : NULL;
}
Пример #2
0
  bool match(const std::string& token)
  {
    int len = token.length();

    if (len == 0)
      return true;

    bool eq = (_text.compare(_pos, len, token) == 0);
    if (!eq)
      return false;

    if (_nameguard)
      {
	bool token_first_is_alpha = is_name_char(_pos);
	bool follow_is_alpha = is_name_char(_pos + len);

	if (token_first_is_alpha && follow_is_alpha)
	  {
	    /* Check if the token is alphanumeric.  */
	    auto begin = _text.cbegin() + _pos;
	    auto end = begin + len;

	    bool token_is_alnum = find_if(begin, end, 
					  [](char ch) { return !std::isalnum(ch); }) == end;
	    if (token_is_alnum)
	      return false;
	  }
      }

    move(len);
    return true;
  }
Пример #3
0
int get_declarator_token(char *token, char *string_buffer, int position) {
	for (; isspace(string_buffer[position]); ++position);

	if (is_declarator_char(*token = string_buffer[position]))
		*++token = '\0';
	else if (is_name_char(*token)) {
		while (is_name_char(*++token = string_buffer[++position]));
		*token = '\0';
	}

	return position;
}