string.dump - cannot dump functions

Posted by WinkleWinkle on Mon 27 Jun 2011 03:16 AM — 4 posts, 16,148 views.

USA #0
I'm having huge issues in Aardwolf Mushclient v 1040 with string.dump!

I am using the example script in the help file and I'm getting the same error in my plugin as well as a test alias

Run-time error
World: Aardwolf
Immediate execution
[string "Alias: "]:2: cannot dump functions
stack traceback:
[C]: in function 'dump'
[string "Alias: "]:2: in main chunk


The code I'm using is copied from the help file and it is:

function f () print "hello, world" end
s = string.dump (f)
assert (loadstring (s)) () --> hello, world

Now.. when i run this code in http://www.lua.org/cgi-bin/demo, it works fine.. but not in mush. The whole point of string.dump is to dump functions, why is the error message saying "cannot dump functions" ?

WinkleWinkle
USA #1
PS, my test alias looks like this:

<aliases>
<alias
match="__test"
enabled="y"
send_to="12"
sequence="100"
>
<send>function f () print "hello, world" end
s = string.dump (f)
assert (loadstring (s)) () --&gt; hello, world</send>
</alias>
</aliases>


PPS I'm not a new lua coder (using anonymous functions and function pointers before), but i'd be happy if i'm missing soemthing obvious like a requires statement
Australia Forum Administrator #2
Hmm. Two things here. First is, this is because you (or Aardwolf) is using LuaJIT. That does not support dumping functions. I finally worked it out after searching for "cannot dump functions" in the source - that message just isn't there.

But if you Google: luajit "cannot dump functions"

... you will find some matches.

One workaround is to put in the "normal" Lua DLL (the one that ships with standard MUSHclient).

Quote:

... when i run this code in http://www.lua.org/cgi-bin/demo, it works fine.. but not in mush ...


That is because Fiendish is using the LuaJIT DLL.


However I really seriously have to wonder why you are dumping functions. I have written many many lines of Lua code, and I never dump them.

I strongly suggest rethinking your design. There should be no need for dumping functions. Perhaps if you describe what you are trying to achieve?
USA Global Moderator #3
WARNING. If you replace the lua dll with one that is not luajit 2.0, the mapper plugin will fail during backup because it uses FFI. Just, you know, a heads up. Also, performance will suffer.

The new b8 version of luajit supports bytecode dumping and loading, so if you REALLY need to use string.dump just wait a day or so. I'll have the new version up in a snapshot by then. I really doubt you need it, but be happy to know that you'll be able to in the next snapshot.

[EDIT] The new snapshot is up now. https://code.google.com/p/aardwolfclientpackage/downloads/list