本文整理汇总了C++中buzzvm_stack_at函数的典型用法代码示例。如果您正苦于以下问题:C++ buzzvm_stack_at函数的具体用法?C++ buzzvm_stack_at怎么用?C++ buzzvm_stack_at使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了buzzvm_stack_at函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: BuzzSetMap
// proper way to send loooong 1D array
int BuzzSetMap(buzzvm_t vm){
/* Make sure one parameter has been passed */
buzzvm_lnum_assert(vm, 1);
/* Get the parameter */
buzzvm_lload(vm, 1);
buzzvm_type_assert(vm, 1, BUZZTYPE_TABLE); // matrix
/* Get the table */
buzzobj_t t = buzzvm_stack_at(vm, 1);
/* Copy the values into a vector */
std::vector<float> mat;
for(int32_t i = 0; i < buzzdict_size(t->t.value); ++i) {
/* Duplicate the table */
buzzvm_dup(vm);
/* Push the index */
buzzvm_pushi(vm, i);
/* Get the value */
buzzvm_tget(vm);
/* Store it in the vector (assume all values are float, no mistake...) */
mat.push_back((float)buzzvm_stack_at(vm, 1)->f.value);
/* Get rid of the value, now useless */
buzzvm_pop(vm);
}
/* Get a pointer to the controller */
buzzvm_pushs(vm, buzzvm_string_register(vm, "controller", 1));
buzzvm_gload(vm);
/* Copy data into the controller */
reinterpret_cast<CBuzzControllerFootBot*>(buzzvm_stack_at(vm, 1)->u.value)->SetMapParams(mat, Sqrt(buzzdict_size(t->t.value)));
/* Done with the function */
return buzzvm_ret0(vm);
}
开发者ID:isvogor-foi,项目名称:BuzzExt,代码行数:31,代码来源:buzz_controller_footbot.cpp
示例2: buzzvm_ret1
buzzvm_state buzzvm_ret1(buzzvm_t vm) {
/* Pop swarm stack */
if(vm->lsyms->isswarm)
buzzdarray_pop(vm->swarmstack);
/* Pop local symbol table */
buzzdarray_pop(vm->lsymts);
/* Set local symbol table pointer */
vm->lsyms = !buzzdarray_isempty(vm->lsymts) ?
buzzdarray_last(vm->lsymts, buzzvm_lsyms_t) :
NULL;
/* Make sure there's an element on the stack */
buzzvm_stack_assert(vm, 1);
/* Save it, it's the return value to pass to the lower stack */
buzzobj_t ret = buzzvm_stack_at(vm, 1);
/* Pop stack */
buzzdarray_pop(vm->stacks);
/* Set stack pointer */
vm->stack = buzzdarray_last(vm->stacks, buzzdarray_t);
/* Make sure the stack contains at least one element */
buzzvm_stack_assert(vm, 1);
/* Make sure that element is an integer */
buzzvm_type_assert(vm, 1, BUZZTYPE_INT);
/* Use that element as program counter */
vm->oldpc = vm->pc;
vm->pc = buzzvm_stack_at(vm, 1)->i.value;
/* Pop the return address */
buzzvm_pop(vm);
/* Push the return value */
return buzzvm_push(vm, ret);
}
开发者ID:isvogor-foi,项目名称:BuzzExt,代码行数:30,代码来源:buzzvm.c
示例3: buzzvm_swarm_others
int buzzvm_swarm_others(buzzvm_t vm) {
buzzvm_lnum_assert(vm, 1);
/* Get the id of the current swarm */
buzzvm_lload(vm, 0);
buzzvm_pushs(vm, buzzvm_string_register(vm, "id"));
buzzvm_tget(vm);
uint16_t id1 = buzzvm_stack_at(vm, 1)->i.value;
/* Get the swarm entry */
uint8_t* x = buzzdict_get(vm->swarms, &id1, uint8_t);
if(!x) {
vm->state = BUZZVM_STATE_ERROR;
vm->error = BUZZVM_ERROR_SWARM;
return BUZZVM_STATE_ERROR;
}
/* Get the id of the new swarm to create */
buzzvm_lload(vm, 1);
buzzvm_type_assert(vm, 1, BUZZTYPE_INT);
uint16_t id2 = buzzvm_stack_at(vm, 1)->i.value;
/* Add a new entry for the swarm */
uint8_t v = *x ? 0 : 1;
buzzdict_set(vm->swarms, &id2, &v);
/* Send update, if necessary */
if(v)
buzzoutmsg_queue_append_swarm_joinleave(
vm->outmsgs, BUZZMSG_SWARM_JOIN, id2);
/* Create a table to return */
make_table(vm, id2);
/* Return */
return buzzvm_ret1(vm);
}
开发者ID:Exception4U,项目名称:Buzz,代码行数:30,代码来源:buzzswarm.c
示例4: buzzvm_swarm_select
int buzzvm_swarm_select(buzzvm_t vm) {
buzzvm_lnum_assert(vm, 1);
/* Get the id */
buzzvm_lload(vm, 0);
buzzvm_pushs(vm, buzzvm_string_register(vm, "id"));
buzzvm_tget(vm);
uint16_t id = buzzvm_stack_at(vm, 1)->i.value;
/* Get the result of the condition check */
buzzvm_lload(vm, 1);
buzzvm_type_assert(vm, 1, BUZZTYPE_INT);
uint8_t in = buzzvm_stack_at(vm, 1)->i.value;
/* Update the swarm, if known */
if(buzzdict_exists(vm->swarms, &id)) {
/* Store membership */
buzzdict_set(vm->swarms, &id, &in);
/* Send update */
buzzoutmsg_queue_append_swarm_joinleave(
vm->outmsgs,
in ? BUZZMSG_SWARM_JOIN : BUZZMSG_SWARM_LEAVE,
id);
/* Return */
return buzzvm_ret0(vm);
}
else {
vm->state = BUZZVM_STATE_ERROR;
vm->error = BUZZVM_ERROR_SWARM;
return BUZZVM_STATE_ERROR;
}
}
开发者ID:Exception4U,项目名称:Buzz,代码行数:29,代码来源:buzzswarm.c
示例5: buzzvm_pushs
void CBuzzControllerFootBot::UpdateSensors() {
/*
* Update generic sensors
*/
CBuzzController::UpdateSensors();
/*
* Update proximity sensor table
*/
if(m_pcProximity != NULL) {
/* Create empty proximity table */
buzzvm_pushs(m_tBuzzVM, buzzvm_string_register(m_tBuzzVM, "proximity", 1));
buzzvm_pusht(m_tBuzzVM);
buzzobj_t tProxTable = buzzvm_stack_at(m_tBuzzVM, 1);
buzzvm_gstore(m_tBuzzVM);
/* Get proximity readings */
const CCI_FootBotProximitySensor::TReadings& tProxReads = m_pcProximity->GetReadings();
/* Fill into the proximity table */
buzzobj_t tProxRead;
for(size_t i = 0; i < tProxReads.size(); ++i) {
/* Create table for i-th read */
buzzvm_pusht(m_tBuzzVM);
tProxRead = buzzvm_stack_at(m_tBuzzVM, 1);
buzzvm_pop(m_tBuzzVM);
/* Fill in the read */
TablePut(tProxRead, "value", tProxReads[i].Value);
TablePut(tProxRead, "angle", tProxReads[i].Angle);
/* Store read table in the proximity table */
TablePut(tProxTable, i, tProxRead);
}
}
}
开发者ID:MISTLab,项目名称:Buzz,代码行数:31,代码来源:buzz_controller_footbot.cpp
示例6: buzzvm_vstig_setonconflictlost
int buzzvm_vstig_setonconflictlost(struct buzzvm_s* vm) {
buzzvm_lnum_assert(vm, 1);
/* Get vstig id */
buzzvm_lload(vm, 0);
buzzvm_pushs(vm, buzzvm_string_register(vm, "id"));
buzzvm_tget(vm);
uint16_t id = buzzvm_stack_at(vm, 1)->i.value;
/* Look for virtual stigmergy */
buzzvstig_t* vs = buzzdict_get(vm->vstigs, &id, buzzvstig_t);
if(vs) {
/* Virtual stigmergy found */
/* Get closure */
buzzvm_lload(vm, 1);
buzzvm_type_assert(vm, 1, BUZZTYPE_CLOSURE);
/* Clone the closure */
if((*vs)->onconflictlost) free((*vs)->onconflictlost);
(*vs)->onconflictlost = buzzobj_clone(buzzvm_stack_at(vm, 1));
}
else {
/* No virtual stigmergy found, just push false */
/* If this happens, its a bug */
buzzvm_pushnil(vm);
fprintf(stderr, "[BUG] [ROBOT %u] Can't find virtual stigmergy %u\n", vm->robot, id);
}
/* Return the value found */
return buzzvm_ret0(vm);
}
开发者ID:Exception4U,项目名称:Buzz,代码行数:27,代码来源:buzzvstig.c
示例7: buzzvm_gstore
buzzvm_state buzzvm_gstore(buzzvm_t vm) {
buzzvm_stack_assert((vm), 2);
buzzvm_type_assert((vm), 2, BUZZTYPE_STRING);
buzzobj_t str = buzzvm_stack_at((vm), 2);
buzzobj_t o = buzzvm_stack_at((vm), 1);
buzzvm_pop(vm);
buzzvm_pop(vm);
buzzdict_set((vm)->gsyms, &(str->s.value.sid), &o);
return BUZZVM_STATE_READY;
}
开发者ID:isvogor-foi,项目名称:BuzzExt,代码行数:10,代码来源:buzzvm.c
示例8: BuzzRotate
static int BuzzRotate(buzzvm_t vm) {
/* Push the yaw angle */
buzzvm_lload(vm, 1);
/* Create a new angle with that */
CRadians cYaw(buzzvm_stack_at(vm, 1)->f.value);
/* Get pointer to the controller */
buzzvm_pushs(vm, buzzvm_string_register(vm, "controller", 1));
buzzvm_gload(vm);
/* Call function */
reinterpret_cast<CBuzzControllerSpiri*>(buzzvm_stack_at(vm, 1)->u.value)->SetYaw(cYaw);
return buzzvm_ret0(vm);
}
开发者ID:MISTLab,项目名称:Buzz,代码行数:12,代码来源:buzz_controller_spiri.cpp
示例9: BuzzRemoveCS
int BuzzRemoveCS(buzzvm_t vm) {
buzzvm_lnum_assert(vm, 1);
buzzvm_lload(vm, 1);
buzzvm_type_assert(vm, 1, BUZZTYPE_INT);
int id = buzzvm_stack_at(vm, 1)->i.value;
buzzvm_pushs(vm, buzzvm_string_register(vm, "controller", 1));
buzzvm_gload(vm);
reinterpret_cast<CBuzzControllerFootBot*>(buzzvm_stack_at(vm, 1)->u.value)->RemoveCS(id);
return buzzvm_ret0(vm);
}
开发者ID:isvogor-foi,项目名称:BuzzExt,代码行数:13,代码来源:buzz_controller_footbot.cpp
示例10: BuzzSetArgosMap
int BuzzSetArgosMap(buzzvm_t vm) {
buzzvm_lnum_assert(vm, 1);
buzzvm_lload(vm, 1);
buzzvm_type_assert(vm, 1, BUZZTYPE_STRING);
std::string text = buzzvm_stack_at(vm, 1)->s.value.str;
/* Get pointer to the controller */
buzzvm_pushs(vm, buzzvm_string_register(vm, "controller", 1));
buzzvm_gload(vm);
/* Call function */
//printf("Value: %s", buzzvm_stack_at(vm, 1)->s.value.str);
reinterpret_cast<CBuzzControllerFootBot*>(buzzvm_stack_at(vm, 1)->u.value)->SetArgosMap(text);
return buzzvm_ret0(vm);
}
开发者ID:isvogor-foi,项目名称:BuzzExt,代码行数:13,代码来源:buzz_controller_footbot.cpp
示例11: buzzneighbors_broadcast
int buzzneighbors_broadcast(buzzvm_t vm) {
buzzvm_lnum_assert(vm, 2);
/* Get value id argument */
buzzvm_lload(vm, 1);
buzzvm_type_assert(vm, 1, BUZZTYPE_STRING);
/* Get value argument */
buzzvm_lload(vm, 2);
/* Queue a message with (value_id, value) */
buzzoutmsg_queue_append_broadcast(
vm,
buzzvm_stack_at(vm, 2),
buzzvm_stack_at(vm, 1));
return buzzvm_ret0(vm);
}
开发者ID:MISTLab,项目名称:Buzz,代码行数:14,代码来源:buzzneighbors.c
示例12: BuzzGoTo
static int BuzzGoTo(buzzvm_t vm) {
/* Push the vector components */
buzzvm_lload(vm, 1);
buzzvm_lload(vm, 2);
/* Create a new vector with that */
CVector2 cDir(buzzvm_stack_at(vm, 2)->f.value,
buzzvm_stack_at(vm, 1)->f.value);
/* Get pointer to the controller */
buzzvm_pushs(vm, buzzvm_string_register(vm, "controller", 1));
buzzvm_gload(vm);
/* Call function */
reinterpret_cast<CBuzzControllerEFootBot*>(buzzvm_stack_at(vm, 1)->u.value)->SetWheelSpeedsFromVector(cDir);
return buzzvm_ret0(vm);
}
开发者ID:isvogor-foi,项目名称:BuzzExt,代码行数:14,代码来源:buzz_controller_efootbot.cpp
示例13: buzzvm_pushs
void CBuzzControllerFootBot::UpdateSensors() {
/*
* Update generic sensors
*/
CBuzzController::UpdateSensors();
/*
* Update proximity sensor table
*/
if(m_pcProximity != NULL) {
/* Create empty proximity table */
buzzvm_pushs(m_tBuzzVM, buzzvm_string_register(m_tBuzzVM, "proximity", 1));
buzzvm_pusht(m_tBuzzVM);
buzzobj_t tProxTable = buzzvm_stack_at(m_tBuzzVM, 1);
buzzvm_gstore(m_tBuzzVM);
/* Get proximity readings */
const CCI_FootBotProximitySensor::TReadings& tProxReads = m_pcProximity->GetReadings();
/* Fill into the proximity table */
buzzobj_t tProxRead;
for(size_t i = 0; i < tProxReads.size(); ++i) {
/* Create table for i-th read */
buzzvm_pusht(m_tBuzzVM);
tProxRead = buzzvm_stack_at(m_tBuzzVM, 1);
buzzvm_pop(m_tBuzzVM);
/* Fill in the read */
TablePut(tProxRead, "value", tProxReads[i].Value);
TablePut(tProxRead, "angle", tProxReads[i].Angle);
/* Store read table in the proximity table */
TablePut(tProxTable, i, tProxRead);
}
}
/*
* Camera
*/
if(m_pcCamera) {
buzzvm_pushs(m_tBuzzVM, buzzvm_string_register(m_tBuzzVM, "blobs", 1));
buzzvm_pusht(m_tBuzzVM);
buzzobj_t tBlobs = buzzvm_stack_at(m_tBuzzVM, 1);
buzzvm_gstore(m_tBuzzVM);
const CCI_ColoredBlobOmnidirectionalCameraSensor::SReadings& sBlobs = m_pcCamera->GetReadings();
for(size_t i = 0; i < sBlobs.BlobList.size(); ++i) {
buzzvm_pusht(m_tBuzzVM);
buzzobj_t tEntry = buzzvm_stack_at(m_tBuzzVM, 1);
buzzvm_pop(m_tBuzzVM);
TablePut(tBlobs, i, tEntry);
TablePut(tEntry, "distance", sBlobs.BlobList[i]->Distance);
TablePut(tEntry, "angle", sBlobs.BlobList[i]->Angle);
TablePut(tEntry, "color", sBlobs.BlobList[i]->Color);
}
}
}
开发者ID:isvogor-foi,项目名称:BuzzExt,代码行数:50,代码来源:buzz_controller_footbot.cpp
示例14: buzzvm_call
buzzvm_state buzzvm_call(buzzvm_t vm, int isswrm) {
/* Get argument number and pop it */
buzzvm_stack_assert(vm, 1);
buzzvm_type_assert(vm, 1, BUZZTYPE_INT);
int32_t argn = buzzvm_stack_at(vm, 1)->i.value;
buzzvm_pop(vm);
/* Make sure the stack has enough elements */
buzzvm_stack_assert(vm, argn+1);
/* Make sure the closure is where expected */
buzzvm_type_assert(vm, argn+1, BUZZTYPE_CLOSURE);
buzzobj_t c = buzzvm_stack_at(vm, argn+1);
/* Make sure that that data about C closures is correct */
if((!c->c.value.isnative) &&
((c->c.value.ref) >= buzzdarray_size(vm->flist))) {
buzzvm_seterror(vm, BUZZVM_ERROR_FLIST, NULL);
return vm->state;
}
/* Create a new local symbol list copying the parent's */
vm->lsyms =
buzzvm_lsyms_new(isswrm,
buzzdarray_clone(c->c.value.actrec));
buzzdarray_push(vm->lsymts, &(vm->lsyms));
/* Add function arguments to the local symbols */
int32_t i;
for(i = argn; i > 0; --i)
buzzdarray_push(vm->lsyms->syms,
&buzzdarray_get(vm->stack,
buzzdarray_size(vm->stack) - i,
buzzobj_t));
/* Get rid of the function arguments */
for(i = argn+1; i > 0; --i)
buzzdarray_pop(vm->stack);
/* Pop unused self table */
buzzdarray_pop(vm->stack);
/* Push return address */
buzzvm_pushi((vm), vm->pc);
/* Make a new stack for the function */
vm->stack = buzzdarray_new(1, sizeof(buzzobj_t), NULL);
buzzdarray_push(vm->stacks, &(vm->stack));
/* Jump to/execute the function */
if(c->c.value.isnative) {
vm->oldpc = vm->pc;
vm->pc = c->c.value.ref;
}
else buzzdarray_get(vm->flist,
c->c.value.ref,
buzzvm_funp)(vm);
return vm->state;
}
开发者ID:isvogor-foi,项目名称:BuzzExt,代码行数:49,代码来源:buzzvm.c
示例15: buzzneighbors_add
int buzzneighbors_add(buzzvm_t vm,
uint16_t robot,
float distance,
float azimuth,
float elevation) {
if(vm->state != BUZZVM_STATE_READY) return vm->state;
/* Get "neighbors" table */
buzzvm_pushs(vm, buzzvm_string_register(vm, "neighbors", 1));
buzzvm_gload(vm);
buzzvm_type_assert(vm, 1, BUZZTYPE_TABLE);
buzzobj_t nbr = buzzvm_stack_at(vm, 1);
/* Get "data" field */
buzzvm_pushs(vm, buzzvm_string_register(vm, "data", 1));
buzzvm_tget(vm);
if(buzzvm_stack_at(vm, 1)->o.type == BUZZTYPE_NIL) {
/* Empty data, create a new table */
buzzvm_pop(vm);
buzzvm_push(vm, nbr);
buzzvm_pushs(vm, buzzvm_string_register(vm, "data", 1));
buzzvm_pusht(vm);
buzzobj_t data = buzzvm_stack_at(vm, 1);
buzzvm_tput(vm);
buzzvm_push(vm, data);
}
/* When we get here, the "data" table is on top of the stack */
/* Push robot id */
buzzvm_pushi(vm, robot);
/* Create entry table */
buzzobj_t entry = buzzheap_newobj(vm->heap, BUZZTYPE_TABLE);
/* Insert distance */
buzzvm_push(vm, entry);
buzzvm_pushs(vm, buzzvm_string_register(vm, "distance", 1));
buzzvm_pushf(vm, distance);
buzzvm_tput(vm);
/* Insert azimuth */
buzzvm_push(vm, entry);
buzzvm_pushs(vm, buzzvm_string_register(vm, "azimuth", 1));
buzzvm_pushf(vm, azimuth);
buzzvm_tput(vm);
/* Insert elevation */
buzzvm_push(vm, entry);
buzzvm_pushs(vm, buzzvm_string_register(vm, "elevation", 1));
buzzvm_pushf(vm, elevation);
buzzvm_tput(vm);
/* Save entry into data table */
buzzvm_push(vm, entry);
buzzvm_tput(vm);
return vm->state;
}
开发者ID:MISTLab,项目名称:Buzz,代码行数:49,代码来源:buzzneighbors.c
示例16: buzzvstig_put
int buzzvstig_put(buzzvm_t vm) {
buzzvm_lnum_assert(vm, 2);
/* Get vstig id */
id_get();
/* Get key */
buzzvm_lload(vm, 1);
buzzobj_t k = buzzvm_stack_at(vm, 1);
/* Get value */
buzzvm_lload(vm, 2);
buzzobj_t v = buzzvm_stack_at(vm, 1);
/* Look for virtual stigmergy */
const buzzvstig_t* vs = buzzdict_get(vm->vstigs, &id, buzzvstig_t);
if(vs) {
/* Look for the element */
const buzzvstig_elem_t* x = buzzvstig_fetch(*vs, &k);
if(x) {
/* Element found */
if(v->o.type != BUZZTYPE_NIL) {
/* New value is not nil, update the existing element */
(*x)->data = v;
++((*x)->timestamp);
(*x)->robot = vm->robot;
/* Append a PUT message to the out message queue */
buzzoutmsg_queue_append_vstig(vm, BUZZMSG_VSTIG_PUT, id, k, *x);
}
else {
/* New value is nil, must delete the existing element */
/* Make a new element with nil as value to update neighbors */
buzzvstig_elem_t y = buzzvstig_elem_new(
buzzobj_new(BUZZTYPE_NIL), // nil value
(*x)->timestamp + 1, // new timestamp
vm->robot); // robot id
/* Append a PUT message to the out message queue with nil in it */
buzzoutmsg_queue_append_vstig(vm, BUZZMSG_VSTIG_PUT, id, k, y);
/* Delete the existing element */
buzzvstig_remove(*vs, &k);
}
}
else if(v->o.type != BUZZTYPE_NIL) {
/* Element not found and new value is not nil, store it */
buzzvstig_elem_t y = buzzvstig_elem_new(v, 1, vm->robot);
buzzvstig_store(*vs, &k, &y);
/* Append a PUT message to the out message queue */
buzzoutmsg_queue_append_vstig(vm, BUZZMSG_VSTIG_PUT, id, k, y);
}
}
/* Return */
return buzzvm_ret0(vm);
}
开发者ID:isvogor-foi,项目名称:BuzzExt,代码行数:49,代码来源:buzzvstig.c
示例17: buzzneighbors_listen
int buzzneighbors_listen(buzzvm_t vm) {
buzzvm_lnum_assert(vm, 2);
/* Get value id argument */
buzzvm_lload(vm, 1);
buzzvm_type_assert(vm, 1, BUZZTYPE_STRING);
/* Get listener argument */
buzzvm_lload(vm, 2);
buzzvm_type_assert(vm, 1, BUZZTYPE_CLOSURE);
/* Install listener */
buzzdict_set(
vm->listeners,
&buzzvm_stack_at(vm, 2)->s.value.sid,
&buzzvm_stack_at(vm, 1));
return buzzvm_ret0(vm);
}
开发者ID:MISTLab,项目名称:Buzz,代码行数:15,代码来源:buzzneighbors.c
示例18: BuzzShowBorderRobots
int BuzzShowBorderRobots(buzzvm_t vm) {
buzzvm_lnum_assert(vm, 1);
buzzvm_lload(vm, 1);
buzzvm_type_assert(vm, 1, BUZZTYPE_TABLE);
buzzobj_t t = buzzvm_stack_at(vm, 1);
buzzvm_pushs(vm, buzzvm_string_register(vm, "controller", 1));
buzzvm_gload(vm);
std::vector<float> v;
buzzdict_foreach(t->t.value, di_read_elem, &v);
reinterpret_cast<CBuzzControllerFootBot*>(buzzvm_stack_at(vm, 1)->u.value)->m_border_robot_ids = v;
return buzzvm_ret0(vm);
}
开发者ID:isvogor-foi,项目名称:BuzzExt,代码行数:16,代码来源:buzz_controller_footbot.cpp
示例19: buzzvm_function_call
buzzvm_state buzzvm_function_call(buzzvm_t vm,
const char* fname,
uint32_t argc) {
/* Reset the VM state if it's DONE */
if(vm->state == BUZZVM_STATE_DONE)
vm->state = BUZZVM_STATE_READY;
/* Don't continue if the VM has an error */
if(vm->state != BUZZVM_STATE_READY)
return vm->state;
/* Push the function name (return with error if not found) */
buzzvm_pushs(vm, buzzvm_string_register(vm, fname, 0));
/* Get associated symbol */
buzzvm_gload(vm);
/* Make sure it's a closure */
buzzvm_type_assert(vm, 1, BUZZTYPE_CLOSURE);
/* Move closure before arguments */
if(argc > 0) {
buzzdarray_insert(vm->stack,
buzzdarray_size(vm->stack) - argc - 1,
buzzvm_stack_at(vm, 1));
buzzvm_pop(vm);
}
/* Call the closure */
return buzzvm_closure_call(vm, argc);
}
开发者ID:isvogor-foi,项目名称:BuzzExt,代码行数:25,代码来源:buzzvm.c
示例20: buzzvstig_create
int buzzvstig_create(buzzvm_t vm) {
buzzvm_lnum_assert(vm, 1);
/* Get vstig id */
buzzvm_lload(vm, 1);
buzzvm_type_assert(vm, 1, BUZZTYPE_INT);
uint16_t id = buzzvm_stack_at(vm, 1)->i.value;
buzzvm_pop(vm);
/* Look for virtual stigmergy */
const buzzvstig_t* vs = buzzdict_get(vm->vstigs, &id, buzzvstig_t);
if(vs) {
/* Found, destroy it */
buzzdict_remove(vm->vstigs, &id);
}
/* Create a new virtual stigmergy */
buzzvstig_t nvs = buzzvstig_new();
buzzdict_set(vm->vstigs, &id, &nvs);
/* Create a table */
buzzvm_pusht(vm);
/* Add data and methods */
buzzvm_dup(vm);
buzzvm_pushs(vm, buzzvm_string_register(vm, "id", 1));
buzzvm_pushi(vm, id);
buzzvm_tput(vm);
function_register(foreach);
function_register(size);
function_register(put);
function_register(get);
function_register(onconflict);
function_register(onconflictlost);
/* Return the table */
return buzzvm_ret1(vm);
}
开发者ID:isvogor-foi,项目名称:BuzzExt,代码行数:32,代码来源:buzzvstig.c
注:本文中的buzzvm_stack_at函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论