void register_all_PluginShareJS_helper(JSContext* cx, JSObject* global) { JS::RootedObject pluginObj(cx); sdkbox::getJsObjOrCreat(cx, JS::RootedObject(cx, global), "sdkbox.PluginShare", &pluginObj); JS_DefineFunction(cx, pluginObj, "setListener", js_PluginShareJS_PluginShare_setListener, 1, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(cx, pluginObj, "share", js_PluginShareJS_PluginShare_share, 1, JSPROP_READONLY | JSPROP_PERMANENT); // JS_DefineFunction(cx, pluginObj, "shareDialog", js_PluginShareJS_PluginShare_shareDialog, 1, JSPROP_READONLY | JSPROP_PERMANENT); register_constants(cx, pluginObj); }
PyMODINIT_FUNC initgtop(void) { PyObject* module; glibtop_init(); Py_AtExit(gtop_at_exit); module = Py_InitModule("gtop", (PyMethodDef*) gtop_methods); PyType_Ready((PyTypeObject*) &StructType); PyObject_SetAttrString(module, "_Struct", (void*) &StructType); register_constants(module); PyModule_AddObject(module, "siglist", build_siglist()); }
int luaopen_fish(lua_State *L) { luaL_Reg fish_aux[] = { {"state_new", _fish_state_new}, {"state_light", _fish_state_light}, {"block_new", _fish_block_new}, {"block_light", _fish_block_light}, {NULL, NULL}}; luaL_newmetatable(L, "fish::state"); lua_pop(L, 1); luaL_newmetatable(L, "fish::block"); lua_pop(L, 1); lua_newtable(L); luaL_setfuncs(L, fish_aux, 0); luaL_setfuncs(L, fish_module_funcs, 0); register_constants(L); return 1; }
PyMODINIT_FUNC init_lasso(void) { PyObject *m, *d; if (PyType_Ready(&PyGObjectPtrType) < 0) return; m = Py_InitModule3("_lasso", lasso_methods, "_lasso wrapper module"); d = PyModule_GetDict(m); register_constants(d); lasso_wrapper_key = g_quark_from_static_string("PyLasso::wrapper"); Py_INCREF(&PyGObjectPtrType); PyModule_AddObject(m, "PyGObjectPtr", (PyObject *)&PyGObjectPtrType); lasso_init(); lasso_log_set_handler(G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION | G_LOG_LEVEL_MASK, lasso_python_log, NULL); }
int parser_eval(const expr_t *e, long double *r, hashtbl_t *vars) { if (!e || !r) { fprintf(stderr, "eval error: null expression or result var\n"); return 1; } /* load known functions */ static hashtbl_t *functions = NULL; if (unlikely(functions == NULL)) { functions = hashtbl_init(NULL, NULL); register_functions(functions); } /* stash constants into whatever symtab we get */ if (unlikely(vars && !hashtbl_get(vars, "_stashed"))) { register_constants(vars); } const list_t *l = (const list_t*)e; const list_node_t *n = list_last(l); list_t *args = list_init(free, NULL); const symbol_t *s; while (n && (s = (const symbol_t*)list_data(n))) { long double *d = NULL, *v = NULL; long double (*f)(list_t*, size_t); switch (s->type) { case stNumber: d = (long double*)zmalloc(sizeof(long double)); *d = s->number; list_push(args, d); break; case stVariable: if (!vars) { fprintf(stderr, "eval error: no symbol table\n"); list_destroy(args); return 1; } if (!(v = (long double*)hashtbl_get(vars, s->variable))) { fprintf(stderr, "eval error: uninitialized variable [%s]\n", s->variable); list_destroy(args); return 1; } d = (long double*)zmalloc(sizeof(long double)); *d = *v; list_push(args, d); break; case stBinOperator: /* rhs operand */ if (!(v = (long double*)list_pop(args))) { fprintf(stderr, "eval error: missing rhs operand\n"); list_destroy(args); return 1; } case stUniOperator: /* lhs operand, don't pop it... use it to store the result too */ if (!(d = (long double*)list_peek_head(args))) { fprintf(stderr, "eval error: missing lhs operand\n"); list_destroy(args); return 1; } *d = semanter_operator(s->operator, *d, s->type == stBinOperator ? *v : 0.0); free(v); break; case stFunction: if (!(f = (long double(*)(list_t*, size_t))hashtbl_get(functions, s->func.name))) { fprintf(stderr, "eval error: unknown function [%s]\n", s->func.name); list_destroy(args); return 1; } d = (long double*)zmalloc(sizeof(long double)); *d = f(args, s->func.nargs); list_push(args, d); break; } n = list_prev(n); } if (list_size(args) != 1) { fprintf(stderr, "eval error: corrupt args stack\n"); list_destroy(args); return 1; } long double *d = (long double*)list_peek_head(args); *r = *d; list_destroy(args); return 0; }