{"action":"opened","issue":{"url":"https://api.github.com/repos/ChaiScript/ChaiScript/issues/155","labels_url":"https://api.github.com/repos/ChaiScript/ChaiScript/issues/155/labels{/name}","comments_url":"https://api.github.com/repos/ChaiScript/ChaiScript/issues/155/comments","events_url":"https://api.github.com/repos/ChaiScript/ChaiScript/issues/155/events","html_url":"https://github.com/ChaiScript/ChaiScript/issues/155","id":58159606,"number":155,"title":"Direct calls to lambdas doesn't work when store inside objects (+hidden exception)","user":{"login":"WoLfulus","id":412397,"avatar_url":"https://avatars.githubusercontent.com/u/412397?v=3","gravatar_id":"","url":"https://api.github.com/users/WoLfulus","html_url":"https://github.com/WoLfulus","followers_url":"https://api.github.com/users/WoLfulus/followers","following_url":"https://api.github.com/users/WoLfulus/following{/other_user}","gists_url":"https://api.github.com/users/WoLfulus/gists{/gist_id}","starred_url":"https://api.github.com/users/WoLfulus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WoLfulus/subscriptions","organizations_url":"https://api.github.com/users/WoLfulus/orgs","repos_url":"https://api.github.com/users/WoLfulus/repos","events_url":"https://api.github.com/users/WoLfulus/events{/privacy}","received_events_url":"https://api.github.com/users/WoLfulus/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-02-19T02:16:51Z","updated_at":"2015-02-19T02:16:51Z","closed_at":null,"body":"I don't know exactly why this happens, but seems there's a problem when calling lambdas stored inside objects... I thought it was because I was storing it inside a vector of objects, but doing several more tests, this is the result:\r\n\r\nFirst test:\r\n\r\n\t//\r\n\t// Bug\r\n\t//\r\n\r\n\tclass MyObject\r\n\t{\r\n\t\tvar lambda\r\n\t\t\tdef MyObject(lambda)\r\n\t\t{\r\n\t\t\tthis.lambda = lambda\r\n\t\t}\r\n\t}\r\n\r\n\tvar myfunction = fun()\r\n\t{\r\n\t\tlog(\"log\")\r\n\t}\r\n\tvar objects = []\r\n\tvar object = MyObject(myfunction)\r\n\tvar func1 = object.lambda\r\n\tobjects.push_back(object)\r\n\tvar func2 = objects[0].lambda\r\n\r\n\tmyfunction() // OK\r\n\tfunc1() // OK\r\n\tfunc2() // OK\r\n\r\n\t(objects[0].lambda)() // Does nothing\r\n\tobjects[0].lambda() // Does nothing\r\n\t(object.lambda)() // Does nothing\r\n\tobject.lambda() // Does nothing\r\n\r\nI then tried adding an argument to the lambda:\r\n\r\n\r\n\t//\r\n\t// Bug\r\n\t//\r\n\r\n\tclass MyObject\r\n\t{\r\n\t\tvar lambda\r\n\t\t\tdef MyObject(lambda)\r\n\t\t{\r\n\t\t\tthis.lambda = lambda\r\n\t\t}\r\n\t}\r\n\r\n\tvar myfunction = fun(str)\r\n\t{\r\n\t\tlog(str)\r\n\t}\r\n\tvar objects = []\r\n\tvar object = MyObject(myfunction)\r\n\tvar func1 = object.lambda\r\n\tobjects.push_back(object)\r\n\tvar func2 = objects[0].lambda\r\n\r\n\tmyfunction(\"test 1\") // OK... outputs test 1\r\n\tfunc1(\"test 2\") // OK... outputs test 2\r\n\tfunc2(\"test 3\") // OK... outputs test 3\r\n\r\n\t(objects[0].lambda)(\"test 4\") // Fails with an exception\r\n\tobjects[0].lambda(\"test 5\")\r\n\t(object.lambda)(\"test 6\")\r\n\tobject.lambda(\"test 7\")\r\n\r\nThe exception thrown is:\r\n\tError: \"Error with function dispatch for function 'lambda'\" With parameters: (Dynamic_Object).(const string) during evaluation at (..\\Data\\Scripts\\timer.chai 28, 2)\r\n\t\r\n\t  Expected: (Dynamic_Object).()\r\n\r\n\t  ..\\Data\\Scripts\\timer.chai (28, 2) 'objects[0].lambda(\"test 4\")'\r\n\t  from ..\\Data\\Scripts\\main.chai (5, 1) 'use(\"timer.chai\")'\r\n\r\nThis is weird, because on the first test, the function is not called at all, but still no exception is given, and on the second test, the lambda is expecting 0 parameters but the lambda expects one parameter to be passed."}}