[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C Hello World Emacs module

From: Emanuel Berg
Subject: Re: C Hello World Emacs module
Date: Sat, 06 Nov 2021 14:05:30 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Emacs Dynamic Module example with all the fixings:

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]