Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change table access to optionally not create tables if they do not exist #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions src/buzz/argos/buzz_loop_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,20 @@ void BuzzPut(buzzvm_t t_vm,
/****************************************/
/****************************************/

void BuzzTableOpen(buzzvm_t t_vm,
const std::string& str_var) {
bool BuzzTableOpen(buzzvm_t t_vm,
const std::string& str_var,
bool b_create) {
buzzvm_pushs(t_vm, buzzvm_string_register(t_vm, str_var.c_str(), 1));
buzzvm_dup(t_vm);
buzzvm_gload(t_vm);
if(!buzzobj_istable(buzzvm_stack_at(t_vm, 1))) {
if(!b_create) {
return false;
}
buzzvm_pop(t_vm);
buzzvm_pusht(t_vm);
}
return true;
}

/****************************************/
Expand Down Expand Up @@ -168,49 +173,64 @@ void BuzzTablePut(buzzvm_t t_vm,
/****************************************/
/****************************************/

void BuzzTableOpenNested(buzzvm_t t_vm,
int n_key) {
bool BuzzTableOpenNested(buzzvm_t t_vm,
int n_key,
bool b_create) {
buzzvm_dup(t_vm);
buzzvm_pushi(t_vm, n_key);
buzzvm_push(t_vm, buzzvm_stack_at(t_vm, 2));
buzzvm_pushi(t_vm, n_key);
buzzvm_tget(t_vm);
if(!buzzobj_istable(buzzvm_stack_at(t_vm, 1))) {
if(!b_create) {
return false;
}
buzzvm_pop(t_vm);
buzzvm_pusht(t_vm);
}
return true;
}

/****************************************/
/****************************************/

void BuzzTableOpenNested(buzzvm_t t_vm,
float f_key) {
bool BuzzTableOpenNested(buzzvm_t t_vm,
float f_key,
bool b_create) {
buzzvm_dup(t_vm);
buzzvm_pushf(t_vm, f_key);
buzzvm_push(t_vm, buzzvm_stack_at(t_vm, 2));
buzzvm_pushf(t_vm, f_key);
buzzvm_tget(t_vm);
if(!buzzobj_istable(buzzvm_stack_at(t_vm, 1))) {
if(!b_create) {
return false;
}
buzzvm_pop(t_vm);
buzzvm_pusht(t_vm);
}
return true;
}

/****************************************/
/****************************************/

void BuzzTableOpenNested(buzzvm_t t_vm,
const std::string& str_key) {
bool BuzzTableOpenNested(buzzvm_t t_vm,
const std::string& str_key,
bool b_create) {
buzzvm_dup(t_vm);
buzzvm_pushs(t_vm, buzzvm_string_register(t_vm, str_key.c_str(), 0));
buzzvm_push(t_vm, buzzvm_stack_at(t_vm, 2));
buzzvm_pushs(t_vm, buzzvm_string_register(t_vm, str_key.c_str(), 0));
buzzvm_tget(t_vm);
if(!buzzobj_istable(buzzvm_stack_at(t_vm, 1))) {
if(!b_create) {
return false;
}
buzzvm_pop(t_vm);
buzzvm_pusht(t_vm);
}
return true;
}

/****************************************/
Expand Down
28 changes: 20 additions & 8 deletions src/buzz/argos/buzz_loop_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,13 @@ void BuzzPut(buzzvm_t t_vm,
*
* @param t_vm The Buzz VM.
* @param str_var The variable name that stores the table.
* @param b_create Make the table if does not exists [default = true].
* @return bool if successfully opened the table.
* @see BuzzTableClose
*/
void BuzzTableOpen(buzzvm_t t_vm,
const std::string& str_var);
bool BuzzTableOpen(buzzvm_t t_vm,
const std::string& str_var,
bool b_create = true);

/**
* Closes the currently open table and stores it as a global variable.
Expand Down Expand Up @@ -221,10 +224,13 @@ void BuzzTablePut(buzzvm_t t_vm,
*
* @param t_vm The Buzz VM.
* @param n_key The key.
* @param b_create Make the table if does not exists [default = true].
* @return bool if successfully opened the table.
* @see BuzzTableCloseNested
*/
void BuzzTableOpenNested(buzzvm_t t_vm,
int n_key);
bool BuzzTableOpenNested(buzzvm_t t_vm,
int n_key,
bool b_create = true);

/**
* Opens a table nested in the currently open table.
Expand All @@ -234,10 +240,13 @@ void BuzzTableOpenNested(buzzvm_t t_vm,
*
* @param t_vm The Buzz VM.
* @param f_key The key.
* @param b_create Make the table if does not exists [default = true].
* @return bool if successfully opened the table.
* @see BuzzTableCloseNested
*/
void BuzzTableOpenNested(buzzvm_t t_vm,
float f_key);
bool BuzzTableOpenNested(buzzvm_t t_vm,
float f_key,
bool b_create = true);

/**
* Opens a table nested in the currently open table.
Expand All @@ -247,10 +256,13 @@ void BuzzTableOpenNested(buzzvm_t t_vm,
*
* @param t_vm The Buzz VM.
* @param str_key The key.
* @param b_create Make the table if does not exists [default = true].
* @return bool if successfully opened the table.
* @see BuzzTableCloseNested
*/
void BuzzTableOpenNested(buzzvm_t t_vm,
const std::string& str_key);
bool BuzzTableOpenNested(buzzvm_t t_vm,
const std::string& str_key,
bool b_create = true);

/**
* Closes the currently open table and stores it in the parent table.
Expand Down