Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-23-2007, 08:54 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
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.
__________________

Last edited by Inverness; 06-23-2007 at 09:06 AM..
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 03:16 AM.


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