~jan-kneschke/mysql-proxy/packet-tracking-assertions

« back to all changes in this revision

Viewing changes to lib/sql-tokenizer-lua.c

  • Committer: jan at mysql
  • Date: 2010-05-27 14:19:43 UTC
  • Revision ID: jan@mysql.com-20100527141943-inwv2cohofexa2pb
added entry about #49716 - literals starting with digits

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
                lua_pushinteger(L, token->token_id);
40
40
                return 1;
41
41
        } else if (strleq(key, keysize, C("token_name"))) {
42
 
                size_t token_name_len;
43
 
                const char *token_name = sql_token_get_name(token->token_id, &token_name_len);
44
 
                lua_pushlstring(L, token_name, token_name_len);
 
42
                lua_pushstring(L, sql_token_get_name(token->token_id));
45
43
                return 1;
46
44
        } else {
47
45
                luaL_error(L, "tokens[...] has no %s field", key);
58
56
        return proxy_getmetatable(L, methods);
59
57
}       
60
58
 
61
 
/**
62
 
 * get a token from the tokens array
63
 
 *
64
 
 */
 
59
 
65
60
static int proxy_tokenize_get(lua_State *L) {
66
61
        GPtrArray *tokens = *(GPtrArray **)luaL_checkself(L); 
67
62
        int ndx = luaL_checkinteger(L, 2);
78
73
        }
79
74
 
80
75
        token = tokens->pdata[ndx - 1];
81
 
        if (NULL == token) {
82
 
                lua_pushnil(L);
83
 
 
84
 
                return 1;
85
 
        }
86
76
 
87
77
        token_p = lua_newuserdata(L, sizeof(token));                          /* (sp += 1) */
88
78
        *token_p = token;
93
83
        return 1;
94
84
}
95
85
 
96
 
/**
97
 
 * a settor for the tokens
98
 
 *
99
 
 * only allow to unset a token in the tokens array to free its memory
100
 
 */
101
 
static int proxy_tokenize_set(lua_State *L) {
102
 
        GPtrArray *tokens = *(GPtrArray **)luaL_checkself(L); 
103
 
        int ndx = luaL_checkinteger(L, 2);
104
 
        sql_token *token;
105
 
 
106
 
        luaL_checktype(L, 3, LUA_TNIL); /* for now we can only use = nil */
107
 
 
108
 
        if (tokens->len > G_MAXINT) {
109
 
                return 0;
110
 
        }
111
 
 
112
 
        /* lua uses 1 is starting index */
113
 
        if (ndx < 1 || ndx > (int)tokens->len) {
114
 
                return 0;
115
 
        }
116
 
 
117
 
        token = tokens->pdata[ndx - 1];
118
 
        if (NULL != token) {
119
 
                sql_token_free(token);
120
 
                tokens->pdata[ndx - 1] = NULL;
121
 
        }
122
 
 
123
 
        return 0;
124
 
}
125
 
 
126
 
 
127
86
static int proxy_tokenize_len(lua_State *L) {
128
87
        GPtrArray *tokens = *(GPtrArray **)luaL_checkself(L); 
129
88
 
144
103
static int sql_tokenizer_lua_getmetatable(lua_State *L) {
145
104
        static const struct luaL_reg methods[] = {
146
105
                { "__index", proxy_tokenize_get },
147
 
                { "__newindex", proxy_tokenize_set },
148
106
                { "__len",   proxy_tokenize_len },
149
107
                { "__gc",   proxy_tokenize_gc },
150
108
                { NULL, NULL },