Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Function Import (https://forums.graalonline.com/forums/showthread.php?t=74817)

Inverness 06-23-2007 08:54 AM

Function Import
 
I had requested this feature along time ago and the new function objects have made it possible now.

This will create function pointers in an object. Variable list:
fromobj - Object, The object you want to import functions from.
toobj - Object, The object you want to import functions to.
fromprefix - String, Only import functions starting with this text. If null, all functions imported.
toprefix - String, Imported functions will be prefixed with this.
events - Boolean, Should functions starting with "on" be included in the operations?
PHP Code:

public function import(fromobjtoobjfromprefixtoprefixevents) {
  
temp.vars 0;
  
temp.0;
  
  if (
fromobj.type() != || toobj.type() != 2) {
    echo(
"System: Import Error");
    return;
  }
  
vars fromobj.getFunctions();
  if (
fromprefix != null) {
    for (
ivars) {
      if (
i.starts("on") && events == false)
        continue;
      if (
fromobj.(@ i).starts(fromprefix)) {
        if (
toprefix == null) {
          
toobj.(@ i) = fromobj.(@ i);
          
toobj.importedfunctions.add(i);
        }
        else {
          
toobj.(@ toprefix i) = fromobj.(@ i);
          
toobj.importedfunctions.add(toprefix i);
        }
      }
    }
  }
  else {
    for (
ivars) {
      if (
i.starts("on") && events == false)
        continue;
      if (
toprefix == null) {
        
toobj.(@ i) = fromobj.(@ i);
        
toobj.importedfunctions.add(i);
      }
      else {
        
toobj.(@ toprefix i) = fromobj.(@ i);
        
toobj.importedfunctions.add(toprefix i);
      }
    }
  }
}
public function 
deport(obj) {
  
temp.vars 0;
  
temp.0;
  
  
vars obj.importedfunctions;
  for (
ivars) {
    
obj.(@ i) = null;
  }


Example:
PHP Code:

// WEAPON: InverTest
function testf(text) {
  echo(
"TESTF: " text);
}
function 
test2(text) {
  echo(
"Test2: " text);


PHP Code:

// WEAPON: InverTest2
function onCreated() {
  
System.import(InverTestthis"test"nullfalse); // importing functions that start with 'test'
  
testf("ZOMG");
  
test2("RAWR");
  
System.deport(this); // removes imported functions


PHP Code:

// Example script
function onCreated() {
  
System.import(MudControlthisnull"mud_"false);
  
// Importing all functions from MudControl and prefixing with mud_ to remove conflict.


I've also noted that using this method can be used even if the imported functions are not public.

coreys 06-23-2007 09:20 AM

Awesome stuff, Inver...
Will you bear my children?
:D

Chompy 06-23-2007 05:24 PM

Really, reallly, really Nice Invern :D

Inverness 06-23-2007 06:09 PM

ego++

zokemon 06-23-2007 09:53 PM

Quote:

Originally Posted by Inverness (Post 1321521)
ego++

NPC Code:
if (this.thread) {
temp.e = ego;
findplayer("Inverness").ego++;
}
if (findplayer("Inverness").ego > e) findplayer("Inverness").badadditude--;



Yay or nay?

Inverness 06-24-2007 11:46 AM

Quote:

Originally Posted by zokemon (Post 1321606)
NPC Code:
if (this.thread) {
temp.e = ego;
findplayer("Inverness").ego++;
}
if (findplayer("Inverness").ego > e) findplayer("Inverness").badadditude--;



Yay or nay?

What is "additude"?


All times are GMT +2. The time now is 03:02 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.