implement direct variable queries & local scopes
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Pytave |
Fix Committed
|
Undecided
|
highegg |
Bug Description
an enhancement towards more convenient working with variables in Octave's current scope
summary of changes:
setvar, getvar and isvar are implemented to set, get and test existence of variables.
this allows doing things like
pytave.setvar("x", 1)
pytave.eval(0,"x += 1")
x = pytave.getvar("x")
push_scope and pop_scope are provided to create an anonymous scope and push it on Octave's call stack,
to prevent cluttering other variables if nested calls to pytave are in effect.
pytave.push_scope()
pytave.setvar("x", something)
pytave.eval(0, "... do something with x)
pytave.pop_scope() # wipes out x and restores its previous value, if any
of course, for proper safety, try/finally block should be used to ensure the cleanup. for convenience, a local_scope decorator is provided that encloses a whole function in push_scope/
@pytave.local_scope
def my_oct_add(x,y):
pytave.
pytave.
result, = pytave.eval(1, "x + y")
return result
this function, when called, will not affect the top-level values of x and y, if any.
patch attached
Changed in pytave: | |
assignee: | nobody → highegg (highegg) |
status: | New → Fix Committed |