/*
 * SPDX-FileCopyrightText: 2013 Koka El Kiwi <kokakiwi@kokakiwi.net>
 * SPDX-FileCopyrightText: 2015-2026 Sébastien Helleu <flashcode@flashtux.org>
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#ifndef WEECHAT_PLUGIN_JS_H
#define WEECHAT_PLUGIN_JS_H

#include <v8.h>

#ifdef __cplusplus
#ifdef _WIN32
#define EXPORT extern "C" __declspec (dllexport)
#else
#define EXPORT extern "C"
#endif /* _WIN32 */
#else
#define EXPORT
#endif /* __cplusplus */

#define weechat_plugin weechat_js_plugin
#define JS_PLUGIN_NAME "javascript"
#define JS_PLUGIN_PRIORITY 4060

#define JS_CURRENT_SCRIPT_NAME ((js_current_script) ? js_current_script->name : "-")

class WeechatJsV8;

extern struct t_weechat_plugin *weechat_js_plugin;

extern struct t_plugin_script_data js_data;

extern int js_quiet;
extern struct t_plugin_script *js_scripts;
extern struct t_plugin_script *last_js_script;
extern struct t_plugin_script *js_current_script;
extern struct t_plugin_script *js_registered_script;
extern const char *js_current_script_filename;
extern WeechatJsV8 *js_current_interpreter;

extern v8::Handle<v8::Object> weechat_js_hashtable_to_object (struct t_hashtable *hashtable);
extern struct t_hashtable *weechat_js_object_to_hashtable (v8::Handle<v8::Object> obj,
                                                           int size,
                                                           const char *type_keys,
                                                           const char *type_values);
extern void *weechat_js_exec (struct t_plugin_script *script,
                              int ret_type, const char *function,
                              const char *format, void **argv);

#endif /* WEECHAT_PLUGIN_JS_H */
