More small improvements.
parent
02bced0b5d
commit
22d6df9927
|
@ -17,6 +17,20 @@ Context::~Context() {
|
|||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
bool Context::contains_function(std::string name)
|
||||
{
|
||||
return contains_sfunction(name) || contains_nfunction(name);
|
||||
}
|
||||
|
||||
bool Context::contains_sfunction(std::string name)
|
||||
{
|
||||
return this->registered_sfunctions.count(name) == 1;
|
||||
}
|
||||
|
||||
bool Context::contains_nfunction(std::string name)
|
||||
{
|
||||
return this->registered_functions.count(name);
|
||||
}
|
||||
|
||||
void Context::register_function(std::string name, PointerToNativeFunction f)
|
||||
{
|
||||
|
|
|
@ -34,13 +34,17 @@ public:
|
|||
void add(std::string name, SenchaObject object);
|
||||
void set(std::string name, SenchaObject object);
|
||||
SenchaObject get(std::string name);
|
||||
bool contains_function(std::string name);
|
||||
bool contains_sfunction(std::string name);
|
||||
bool contains_nfunction(std::string name);
|
||||
std::map<std::string, PointerToNativeFunction> registered_functions;
|
||||
std::map<std::string, SenchaFunction *> registered_sfunctions;
|
||||
virtual ~Context();
|
||||
|
||||
private:
|
||||
unsigned int index;
|
||||
|
||||
std::map<std::string, PointerToNativeFunction> registered_functions;
|
||||
std::map<std::string, SenchaFunction *> registered_sfunctions;
|
||||
|
||||
|
||||
std::map<std::string, SenchaObject> object_store;
|
||||
};
|
||||
|
|
|
@ -28,12 +28,12 @@ Context * ContextManager::create_new_context()
|
|||
SenchaObject ContextManager::execute_function(std::string name, std::vector<ASTExpression *> arguments)
|
||||
{
|
||||
SenchaObject result;
|
||||
if(contexts["global"]->registered_functions.count(name) == 1)
|
||||
if(contexts["global"]->contains_nfunction(name))
|
||||
{
|
||||
result = contexts["global"]->registered_functions[name](arguments);
|
||||
}
|
||||
|
||||
else if(contexts["global"]->registered_sfunctions.count(name) == 1)
|
||||
else if(contexts["global"]->contains_sfunction(name))
|
||||
{
|
||||
std::vector<SenchaObject> evaluated_arguments;
|
||||
for(auto argument : arguments)
|
||||
|
|
|
@ -120,8 +120,7 @@ bool Parser::is_type()
|
|||
|
||||
bool Parser::is_function_name()
|
||||
{
|
||||
if(context_manager->context("global")->registered_functions.count(tok_value) == 1 ||
|
||||
context_manager->context("global")->registered_sfunctions.count(tok_value))
|
||||
if(context_manager->context("global")->contains_function(tok_value))
|
||||
{
|
||||
read_next();
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue