Merge branch 'master' into 2011-09-09-CxScript
Conflicts: include/chaiscript/language/chaiscript_engine.hpp include/chaiscript/language/chaiscript_eval.hpp
This commit is contained in:
@@ -496,28 +496,24 @@ namespace chaiscript
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Swaps out the stack with a new stack
|
||||
* \returns the old stack
|
||||
* \param[in] s The new stack
|
||||
*/
|
||||
Stack set_stack(const Stack &s)
|
||||
{
|
||||
Stack old = m_stack_holder->stack;
|
||||
m_stack_holder->stack = s;
|
||||
return old;
|
||||
}
|
||||
|
||||
Stack new_stack() const
|
||||
/// Pushes a new stack on to the list of stacks
|
||||
void new_stack()
|
||||
{
|
||||
Stack s(new Stack::element_type());
|
||||
s->push_back(Scope());
|
||||
return s;
|
||||
m_stack_holder->stacks.push_back(s);
|
||||
}
|
||||
|
||||
void pop_stack()
|
||||
{
|
||||
m_stack_holder->stacks.pop_back();
|
||||
}
|
||||
|
||||
/// \returns the current stack
|
||||
Stack get_stack() const
|
||||
{
|
||||
return m_stack_holder->stack;
|
||||
return m_stack_holder->stacks.back();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -566,8 +562,8 @@ namespace chaiscript
|
||||
if (funcs.size() == 1)
|
||||
{
|
||||
// Return the first item if there is only one,
|
||||
// no reason to take the cast of the extra level of dispatch
|
||||
return const_var(*funcs.begin());
|
||||
// no reason to take the cost of the extra level of dispatch
|
||||
return const_var(funcs.front());
|
||||
} else {
|
||||
return Boxed_Value(Const_Proxy_Function(new Dispatch_Function(funcs)));
|
||||
}
|
||||
@@ -668,6 +664,66 @@ namespace chaiscript
|
||||
return functions.find(name) != functions.end();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get a map of all objects that can be seen from the current scope in a scripting context
|
||||
///
|
||||
std::map<std::string, Boxed_Value> get_scripting_objects() const
|
||||
{
|
||||
// We don't want the current context, but one up if it exists
|
||||
StackData &stack = (m_stack_holder->stacks.size()==1)?(*(m_stack_holder->stacks.back())):(*m_stack_holder->stacks[m_stack_holder->stacks.size()-2]);
|
||||
|
||||
std::map<std::string, Boxed_Value> retval;
|
||||
|
||||
// note: map insert doesn't overwrite existing values, which is why this works
|
||||
|
||||
for (StackData::reverse_iterator itr = stack.rbegin(); itr != stack.rend(); ++itr)
|
||||
{
|
||||
retval.insert(itr->begin(), itr->end());
|
||||
}
|
||||
|
||||
// add the global values
|
||||
{
|
||||
chaiscript::detail::threading::shared_lock<chaiscript::detail::threading::shared_mutex> l(m_global_object_mutex);
|
||||
|
||||
retval.insert(m_state.m_global_objects.begin(), m_state.m_global_objects.end());
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get a map of all functions that can be seen from a scripting context
|
||||
///
|
||||
std::map<std::string, Boxed_Value> get_scripting_functions() const
|
||||
{
|
||||
chaiscript::detail::threading::shared_lock<chaiscript::detail::threading::shared_mutex> l(m_mutex);
|
||||
|
||||
std::vector<std::pair<std::string, Proxy_Function> > rets;
|
||||
|
||||
const std::map<std::string, std::vector<Proxy_Function> > &functions = get_functions_int();
|
||||
|
||||
std::map<std::string, Boxed_Value> retval;
|
||||
|
||||
for (std::map<std::string, std::vector<Proxy_Function> >::const_iterator itr = functions.begin();
|
||||
itr != functions.end();
|
||||
++itr)
|
||||
{
|
||||
if (itr->second.size() == 1)
|
||||
{
|
||||
// Return the first item if there is only one,
|
||||
// no reason to take the cost of the extra level of dispatch
|
||||
retval.insert(std::make_pair(itr->first, const_var(itr->second.front())));
|
||||
} else {
|
||||
retval.insert(std::make_pair(itr->first, Boxed_Value(Const_Proxy_Function(new Dispatch_Function(itr->second)))));
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a vector of all registered functions
|
||||
*/
|
||||
@@ -854,7 +910,7 @@ namespace chaiscript
|
||||
*/
|
||||
StackData &get_stack_data() const
|
||||
{
|
||||
return *(m_stack_holder->stack);
|
||||
return *(m_stack_holder->stacks.back());
|
||||
}
|
||||
|
||||
const std::map<std::string, std::vector<Proxy_Function> > &get_functions_int() const
|
||||
@@ -1016,12 +1072,13 @@ namespace chaiscript
|
||||
struct Stack_Holder
|
||||
{
|
||||
Stack_Holder()
|
||||
: stack(new StackData())
|
||||
{
|
||||
stack->push_back(Scope());
|
||||
Stack s(new StackData());
|
||||
s->push_back(Scope());
|
||||
stacks.push_back(s);
|
||||
}
|
||||
|
||||
Stack stack;
|
||||
std::deque<Stack> stacks;
|
||||
};
|
||||
|
||||
std::vector<Dynamic_Cast_Conversion> m_conversions;
|
||||
|
Reference in New Issue
Block a user