本文整理汇总了C++中call_function函数的典型用法代码示例。如果您正苦于以下问题:C++ call_function函数的具体用法?C++ call_function怎么用?C++ call_function使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了call_function函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: simpsons_approx
double simpsons_approx(int fun,double lo,double hi){//do a simpson's approximation on the appropriate function over the specified interval
double p1=(hi-lo)/6.0;
double pLo=call_function(fun,lo);
double pAv=4.0 * call_function(fun,(lo+hi)/2 );
double pHi=call_function(fun,hi);
return p1*( pLo+pAv+pHi );
}
示例2: create_object
void
create_object(struct object *ob)
{
int i;
if (!(ob->flags & O_CREATED))
{
ob->flags |= O_CREATED;
ob->created = current_time;
for (i = 0; i < (int)ob->prog->num_inherited; i++)
if (!(ob->prog->inherit[i].type & TYPE_MOD_SECOND))
{
if (ob->prog->inherit[i].prog->ctor_index !=
(unsigned short) -1)
{
call_function(ob, i,
(unsigned int)ob->prog->inherit[i].prog->ctor_index, 0);
pop_stack();
}
}
if (search_for_function("create", ob->prog))
{
call_function(ob, function_inherit_found,
(unsigned int)function_index_found, 0);
pop_stack();
}
}
}
示例3: func_name
const SpObject *SpVM::eval(const SpExpr *expr, SpEnv *env) {
// check whether this expression is an atom or a function call
if (expr->head()->type() == TOKEN_FUNCTION_CALL) {
// this is a function call expression
std::string func_name(expr->head()->value());
// we find the function associated with this name in the given environment
const SpObject *obj = resolve(func_name, env);
if (obj == NULL || obj->type() != T_FUNCTION) RUNTIME_ERROR_F("'%s' is not a function", func_name.c_str());
// now call the function
return call_function(func_name,
static_cast<const SpFunction *>(obj->self()), expr, env);
} else {
// evaluate this atom
std::string val = expr->head()->value();
switch (expr->head()->type()) {
case TOKEN_NAME: {
const SpObject *obj = resolve(val, env);
if (obj == NULL)
RUNTIME_ERROR_F("Undeclared variable '%s'", val.c_str());
return obj->shallow_copy();
}
case TOKEN_NUMERIC:
return new SpIntValue(atoi(val.c_str()));
case TOKEN_CLOSURE:
// the closure expression is stored in the first argument of the
// object expression
return new SpRefObject(new SpClosure(ArgList(), NULL, *expr->cbegin()));
default:
RUNTIME_ERROR("Unsupported operation");
}
}
}
示例4: get_type
int get_type(char *format, va_list args)
{
int id;
int count[1];
count[0] = 0;
count[1] = 0;
while (format[count[1]] != '\0')
{
id = -1;
if (format[count[1]] == '%')
{
id = get_id(count[1], format, "csdioxXbpSuf");
if (id >= 0)
{
count[0] += call_function(id, args);
count[1]++;
}
count[1]++;
}
else
get_type_next(format, count);
}
return (count[0]);
}
示例5: call_function
/**
* \brief Calls the on_closed() method of the object on top of the stack.
*/
void LuaContext::on_closed()
{
if (find_method("on_closed"))
{
call_function(1, 0, "on_closed");
}
}
示例6: get_function_value
int32 interpreter::get_function_value(int32 f, uint32 param_count) {
int32 result;
if(!f) {
params.clear();
return 0;
}
no_action++;
call_depth++;
if (call_function(f, param_count, 1)) {
if (lua_isboolean(current_state, -1))
result = lua_toboolean(current_state, -1);
else
result = lua_tointeger(current_state, -1);
lua_pop(current_state, 1);
no_action--;
call_depth--;
if(call_depth == 0) {
pduel->release_script_group();
pduel->restore_assumes();
}
return result;
}
no_action--;
call_depth--;
if(call_depth == 0) {
pduel->release_script_group();
pduel->restore_assumes();
}
return OPERATION_FAIL;
}
示例7: check_condition
int32 interpreter::check_condition(int32 f, uint32 param_count) {
int32 result;
if(!f) {
params.clear();
return TRUE;
}
no_action++;
call_depth++;
if (call_function(f, param_count, 1)) {
result = lua_toboolean(current_state, -1);
lua_pop(current_state, 1);
no_action--;
call_depth--;
if(call_depth == 0) {
pduel->release_script_group();
pduel->restore_assumes();
}
return result;
}
no_action--;
call_depth--;
if(call_depth == 0) {
pduel->release_script_group();
pduel->restore_assumes();
}
return OPERATION_FAIL;
}
示例8: evaluate_variable
bool evaluate_variable(const object& variable_name)
{
object result;
// std::cout << "GET VARIABLE" << std::endl;
if(get_variable(variable_name.data.variable, &result) == OK)
{
// std::cout << "GET VARIABLE" << std::endl;
// Auto call zero argument functions when they are found.
if(result.type == FUNCTION)
{
if(result.data.function->arguments.size() == 1)
{
object arguments; // empty, won't be used by call_function so no need to initialize
call_function(result, result, arguments);
}
}
optic_stack.push_back(result); // result is already a copy, no need to copy again
return true;
}
else
{
out() << "Variable " << reverse_variable_name_lookup[variable_name.data.variable] << " not found." << std::endl;
clear_stack();
return false;
}
}
示例9: push_callback
/**
* \brief Executes the callback of a timer.
*
* Then, if the callback returns \c true, the timer is rescheduled,
* otherwise it is discarded.
*
* Does nothing if the timer is already finished.
*
* \param timer The timer to execute.
*/
void LuaContext::do_timer_callback(Timer& timer) {
Debug::check_assertion(timer.is_finished(), "This timer is still running");
const std::map<Timer*, LuaTimerData>::iterator it = timers.find(&timer);
if (it != timers.end() && it->second.callback_ref != LUA_REFNIL) {
const int callback_ref = it->second.callback_ref;
push_callback(callback_ref);
const bool success = call_function(0, 1, "timer callback");
bool repeat = false;
if (success) {
repeat = lua_isboolean(l, -1) && lua_toboolean(l, -1);
lua_pop(l, 1);
}
if (repeat) {
// The callback returned true: reschedule the timer.
timer.set_expiration_date(timer.get_expiration_date() + timer.get_initial_duration());
if (timer.is_finished()) {
// Already finished: this is possible if the duration is smaller than
// the main loop stepsize.
do_timer_callback(timer);
}
}
else {
cancel_callback(callback_ref);
it->second.callback_ref = LUA_REFNIL;
timers_to_remove.push_back(&timer);
}
}
}
示例10: main
int
main() {
lua_State *L = luaL_newstate();
call_function(L);
lua_close(L);
return 0;
}
示例11: Function_call
static HRESULT Function_call(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r)
{
FunctionInstance *function;
IDispatch *this_obj = NULL;
unsigned cnt = 0;
HRESULT hres;
TRACE("\n");
if(!(function = function_this(jsthis)))
return throw_type_error(ctx, JS_E_FUNCTION_EXPECTED, NULL);
if(argc) {
if(!is_undefined(argv[0]) && !is_null(argv[0])) {
hres = to_object(ctx, argv[0], &this_obj);
if(FAILED(hres))
return hres;
}
cnt = argc-1;
}
hres = call_function(ctx, function, this_obj, cnt, argv+1, r);
if(this_obj)
IDispatch_Release(this_obj);
return hres;
}
示例12: push_ref
/**
* \brief Executes the callback of a timer.
*
* Then, if the callback returns \c true, the timer is rescheduled,
* otherwise it is discarded.
*
* Does nothing if the timer is already finished.
*
* \param timer The timer to execute.
*/
void LuaContext::do_timer_callback(const TimerPtr& timer) {
Debug::check_assertion(timer->is_finished(), "This timer is still running");
auto it = timers.find(timer);
if (it != timers.end() &&
!it->second.callback_ref.is_empty()) {
ScopedLuaRef& callback_ref = it->second.callback_ref;
push_ref(l, callback_ref);
const bool success = call_function(0, 1, "timer callback");
bool repeat = false;
if (success) {
repeat = lua_isboolean(l, -1) && lua_toboolean(l, -1);
lua_pop(l, 1);
}
if (repeat) {
// The callback returned true: reschedule the timer.
timer->set_expiration_date(timer->get_expiration_date() + timer->get_initial_duration());
if (timer->is_finished()) {
// Already finished: this is possible if the duration is smaller than
// the main loop stepsize.
do_timer_callback(timer);
}
}
else {
callback_ref.clear();
timers_to_remove.push_back(timer);
}
}
}
示例13: epic_call
static VALUE epic_call (VALUE module, VALUE string)
{
char *funcval;
RUBY_STARTUP
funcval = call_function(my_string, "");
return rb_str_new(funcval, strlen(funcval));
}
示例14: do_test_run
static void do_test_run(struct code_chunks *chunk)
{
/* type-1 function */
char df1[] = {
0x64, 0x00, 0x00, 0x00, /* 100 */
'x', 0x00, 0x00, 0x00, /* 'x' */
0xC8, 0x00, 0x00, 0x00, /* 200 */
};
/* type-2 function */
char *name = "mygirl";
char df2[] = {
0x00, 0x00, 0x00, 0x00, /* name */
0x04, 0x00, 0x00, 0x00 /* 4 */
};
/* type-3 function */
int fibo;
char df3[] = {
0x0f, 0x00, 0x00, 0x00, /* 15 */
0x00, 0x00, 0x00, 0x00 /* fibo */
};
char number[15];
char df4[] = {
0xde, 0xad, 0xbe, 0xef,
0x00, 0x00, 0x00, 0x00 /* number */
};
char df5[] = { };
ptr2char(df2, name);
ptr2char((char *)df3 + 4, &fibo);
ptr2char((char *)df4 + 4, number);
call_function(chunk, FUNC_TYPE1, df1);
call_function(chunk, FUNC_TYPE2, df2);
call_function(chunk, FUNC_TYPE3, df3);
printf("%s: fibo value returned: %d\n", __func__, fibo);
call_function(chunk, FUNC_TYPE5, df5);
call_function(chunk, FUNC_TYPE4, df4);
printf("%s: original: %d, reversed: %s\n", __func__, *(int *)df4, number);
}
示例15: query
uint64_t query(factor Factor) const
{
const auto Diff = call_function(QueryPerformanceCounter) - m_StartTime;
const auto Frequency = get_frequency();
const auto Whole = Diff / Frequency;
const auto Fraction = Diff % Frequency;
return Whole * Factor + (Fraction * Factor) / Frequency;
}