Skip to content
Snippets Groups Projects
Select Git revision
  • d1f27164f5546f5206c1be3b3af60cf0b12639d5
  • master default protected
  • 9.0
  • 8.0
  • nt-tools
  • 7.8
  • 7.6
  • 7.4
  • 7.2
  • 7.0
  • 0.6
  • rosuav/latex-markdown-renderer
  • rxnpatch/rxnpatch
  • marcus/gobject-introspection
  • rxnpatch/8.0
  • rosuav/pre-listening-ports
  • rosuav/async-annotations
  • rosuav/pgsql-ssl
  • rxnpatch/rxnpatch-broken/2023-10-06T094250
  • grubba/fdlib
  • grubba/wip/sakura/8.0
  • v8.0.2020
  • v8.0.2018
  • v8.0.2016
  • v8.0.2014
  • v8.0.2012
  • v8.0.2008
  • v8.0.2006
  • v8.0.2004
  • v8.0.2002
  • v8.0.2000
  • v8.0.1998
  • v8.0.1996
  • v8.0.1994
  • v8.0.1992
  • v8.0.1990
  • v8.0.1988
  • v8.0.1986
  • rxnpatch/clusters/8.0/2025-04-29T124414
  • rxnpatch/2025-04-29T124414
  • v8.0.1984
41 results

mapping.c

Blame
  • add_efun.c 2.72 KiB
    /*\
    ||| This file a part of uLPC, and is copyright by Fredrik Hubinette
    ||| uLPC is distributed as GPL (General Public License)
    ||| See the files COPYING and DISCLAIMER for more information.
    \*/
    #include "add_efun.h"
    #include "macros.h"
    #include "program.h"
    #include "lpc_types.h"
    #include "stralloc.h"
    #include "memory.h"
    #include "interpret.h"
    
    static struct hash_table *efun_hash = 0;
    
    struct efun *lookup_efun(struct lpc_string *name)
    {
      struct hash_entry *h;
    
      if(!efun_hash) return 0;
      h=hash_lookup(efun_hash, name);
      if(!h) return 0;
      return BASEOF(h, efun, link);
    }
    
    void low_add_efun(struct lpc_string *name, struct svalue *fun)
    {
      struct efun *parent;
      
      parent=lookup_efun(name);
    
      if(!parent)
      {
        if(!fun) return;
    
        parent=ALLOC_STRUCT(efun);
        copy_shared_string(parent->link.s,name);
        efun_hash=hash_insert(efun_hash, &parent->link);
      }else{
        free_svalue(& parent->function);
    
        /* Disable efun */
        if(!fun)
        {
          efun_hash=hash_unlink(efun_hash, &parent->link);
          free_string(parent->link.s);
          free((char *)parent);
          return;
        }
      }
    
      assign_svalue_no_free(& parent->function, fun);
    }
    
    
    struct callable *make_callable(c_fun fun,
    			       char *name,
    			       char *type,
    			       INT16 flags,
    			       optimize_fun optimize,
    			       docode_fun docode)
    {
      struct callable *f;
      f=ALLOC_STRUCT(callable);
      f->refs=1;
      f->function=fun;
      f->name=make_shared_string(name);
      f->type=parse_type(type);
      f->flags=flags;
      f->docode=docode;
      f->optimize=optimize;
      return f;
    }
    
    void really_free_callable(struct callable *fun)
    {
      free_string(fun->type);
      free_string(fun->name);
      free((char *)fun);
    }
    
    void add_efun2(char *name,
    	       c_fun fun,
    	       char *type,
    	       INT16 flags,
    	       optimize_fun optimize,
    	       docode_fun docode)
    {
      struct svalue s;
      struct lpc_string *n;
    
      n=make_shared_string(name);
      s.type=T_FUNCTION;
      s.subtype=-1;
      s.u.efun=make_callable(fun, name, type, flags, optimize, docode);
      low_add_efun(n, &s);
      free_svalue(&s);
      free_string(n);
    }
    
    void add_efun(char *name, c_fun fun, char *type, INT16 flags)
    {
      add_efun2(name,fun,type,flags,0,0);
    }
    
    static void push_efun_entry(struct hash_entry *h)
    {
      struct efun *f;
      check_stack(1);
      f=BASEOF(h, efun, link);
      push_string(f->link.s);
      f->link.s->refs++;
      copy_svalues_recursively_no_free(sp,& f->function,1,0);
      sp++;
    }
    
    void push_all_efuns_on_stack()
    {
      if(efun_hash)
        map_hashtable(efun_hash,push_efun_entry);
    }
    
    static void free_one_hashtable_entry(struct hash_entry *h)
    {
      struct efun *f;
      f=BASEOF(h, efun, link);
      free_svalue(& f->function);
      free((char *)f);
    }
    
    void cleanup_added_efuns()
    {
      if(efun_hash)
      {
        free_hashtable(efun_hash,free_one_hashtable_entry);
        efun_hash=0;
      }
      
    }