int Parser_AddConstant(Parser* parser, Value* value) { Function* function = parser->function; ASSERT(function->numConstants < 262144); // We can't store a nil value in a table, so if it's a nil value we need // to use some other value to indicate that. We use the constant table // itself since this will never appear otherwise. Value _value; if (Value_GetIsNil(value)) { SetValue(&_value, function->constants); value = &_value; } const Value* result = Table_GetTable(parser->L, function->constants, value); if (!Value_GetIsNil(result)) { return Value_GetInteger(result); } Value index; SetValue(&index, function->numConstants); Table_SetTable(parser->L, function->constants, value, &index); ++function->numConstants; return Value_GetInteger(&index); }
void lua_rawgeti(lua_State *L, int index, int n) { Value* table = GetValueForIndex(L, index); luai_apicheck(L, Value_GetIsTable(table) ); const Value* value = Table_GetTable(L, table->table, n); if (value == NULL) { PushNil(L); } else { PushValue(L, value); } }
void lua_rawget(lua_State* L, int index) { Value* table = GetValueForIndex( L, index ); luai_apicheck(L, Value_GetIsTable(table) ); const Value* key = GetValueForIndex(L, -1); const Value* value = Table_GetTable(L, table->table, key); if (value != NULL) { *(L->stackTop - 1) = *value; } else { SetNil(L->stackTop - 1); } }