From: Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: C Hello World Emacs module
Date: Sat, 06 Nov 2021 14:05:30 +0100 [thread overview]
Message-ID: <87r1bto2n9.fsf@zoho.eu> (raw)
In-Reply-To: 87r1cyr4f7.fsf@online.de
Emacs Dynamic Module example with all the fixings:
https://dataswamp.org/~incal/emacs-init/more/dm/
Here's the C. Follow the hyperlink for the Makefile,
header file, and Elisp.
#include "dm.h"
#include <emacs-module.h>
#include <stdio.h>
int plugin_is_GPL_compatible;
int emacs_module_init(struct emacs_runtime* runtime) {
if (runtime->size < (long int)sizeof(*runtime)) {
return 1; // incompatible/mismatch Emacs binary
}
emacs_env* env = runtime->get_environment(runtime);
if (env->size < (long int)sizeof(*env)) {
return 2; // ditto module API
}
int __attribute__((unused)) emacs_version;
if ((long int)sizeof(struct emacs_env_29) <= env->size) {
emacs_version = 29;
}
else {
return 3; // too old Emacs
}
emacs_value hw_func = env->make_function(env, 0, 0, hw, NULL, NULL);
emacs_value hw_symbol = env->intern(env, "hw-func");
emacs_value args[] = {hw_symbol, hw_func};
env->funcall(env, env->intern(env, "defalias"), 2, args);
return 0;
}
emacs_value hw(emacs_env* env,
ptrdiff_t nargs __attribute__((unused)),
emacs_value* args __attribute__((unused)),
void* data __attribute__((unused))) {
emacs_value str = env->make_string(env, "Dynamic Module Operational", 26);
return str;
}
--
underground experts united
https://dataswamp.org/~incal
prev parent reply other threads:[~2021-11-06 13:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-05 10:07 C Hello World Emacs module Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-05 10:37 ` Omar Polo
2021-10-05 11:15 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-05 11:26 ` Omar Polo
2021-10-05 11:47 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-06 7:35 ` Christian Barthel
2021-11-06 13:05 ` Emanuel Berg via Users list for the GNU Emacs text editor [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r1bto2n9.fsf@zoho.eu \
--to=help-gnu-emacs@gnu.org \
--cc=moasenwood@zoho.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).