Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-01-2011, 09:22 AM
MrDunne MrDunne is offline
Registered User
Join Date: Aug 2010
Posts: 38
MrDunne is on a distinguished road
Quote:
Originally Posted by Chompy View Post
Elaborate.
Quote:
Originally Posted by WhiteDragon View Post
There are a few problems.
  • In certain cases, when passing around an anonymous function, you lose the ability to call it. I think the problem is when you call the anonymous function from a different class than it was defined, but I'm not certain exactly when it happens. (If someone wants to debug this, please do.)

    My current hack around this is, given a function temp.f, doing (@temp.f)(), which casts the function pointer to a string like "function_913727", which is a global variable and can be called from anywhere as a result.
  • When a class using anonymous functions is updated, most things break until you update the NPC/Weapon that they are joined to.
Mainly this. There's also this:

PHP Code:
function onCreated() {
  
temp.func myTest();
  (@ 
temp.func)();

  
myOtherTest(function () {
    echo(
"yeah baby");
  });
}

function 
myTest() {
  return function () {
    echo(
"yeah baby");
  };
}

function 
myOtherTest(func) {
  (@ 
func)();

Produces the following:

HTML Code:
Script compiler output for *scratch*:
error: unexpected token: function at line 3: myOtherTest(function () {
error: unexpected token: ( at line 3: myOtherTest(function () {
error: unexpected token: ) at line 3: myOtherTest(function () {
error: unexpected token: ) at line 5: });
error: unexpected token: function at line 13: return function () {
error: unexpected token: ( at line 13: return function () {
error: unexpected token: ) at line 13: return function () {
It doesn't seem right to me.
Reply With Quote
  #2  
Old 07-01-2011, 09:42 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by MrDunne View Post
There's also this: ...
That's a result of the GS2 grammar not being flexible enough. Ideally, anonymous functions would be listed as expressions (so you could put them anywhere you could put, say, true), but they seem to only be allowed in variable assignments (i.e., temp.f = ...).

One nifty hack around this one is, for example, return (temp.f = function () { ... } );. But that's rather ugly and I certainly don't do it .

But yeah, that is indeed another thing that should be changed and should be fairly straightforward.
Reply With Quote
Reply


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:05 AM.


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