News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
Pages (2): « First [1] 2 Next > Last »
MurgaLua Compiler
Author Message
iGame3D
Moderator
***


Posts: 231
Group: Moderators
Joined: Apr 2007
Status: Offline
Reputation: 0
Post: #1
MurgaLua Compiler

Testing Mariels Bezier script I get a

Code:
[string "--[[..."]:23: module 'lib/utils' not found:
no field package.preload['lib/utils']
       no file './lib/utils.lua"
etc ..... etc
[C]: in function 'require'
        [string "--[[..."]:23: in function 'newFunc'
        [string "murgaLua"]:268: in function 'decompileMurgaLua'
        [string ""]:1: in main chunk
        [C]: ?


Pasting the required scripts into the main script gets the compiled version mostly working.
I think its missing an image now.

Yep the event detection script can't find its image as well.

How should we handle that?

lfs.currentdir() returns the User folder by default.

How to get a binary to report its own location?

This post was last modified: 01-31-2008 10:57 PM by iGame3D.

01-31-2008 09:54 PM
Visit this user's website Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #2
RE: MurgaLua Compiler

I'm not sure about a binary, but you can use arg[0] to get the full path to a script. This path can be chopped if you need the directory name:
string.gsub(arg[0],"(.*)/.*","%1")

I'm kinda surprised that FLTK has fl_filename_name (equivalent of basename), but no equivalent of dirname

02-01-2008 12:00 AM
Find all posts by this user Quote this message in a reply
JohnMurga
Administrator
*******


Posts: 381
Group: Administrators
Joined: Apr 2007
Status: Offline
Reputation: 2
Post: #3
RE: MurgaLua Compiler

Try running the "about.lua" script from the latest snapshot.

murgaLua_ExePath is what the runtime uses to find itself ...

And you can use mikshaw's code to chop it up ... On Linux/Mac ...
On Windows you'll have the slashes the other way.

arg[0] "should" work, but it is the C equivalent and won't always point to the right place.

Cheers
JohnM

02-01-2008 02:45 AM
Visit this user's website Find all posts by this user Quote this message in a reply
JohnMurga
Administrator
*******


Posts: 381
Group: Administrators
Joined: Apr 2007
Status: Offline
Reputation: 2
Post: #4
RE: MurgaLua Compiler

iGame3D Wrote:
I think its missing an image now.

How should we handle that?

Two ways to that (sub-optimal at present).

Embed it ... By using the new picture and hex functions to dump as a hex string, and then reload/decode it as hex string at runtime.

Or, get the executable to load it from a location relative to it's own (see previous post).

I will knock up a demo of the first method this week.

Cheers
JohnM

02-01-2008 02:50 AM
Visit this user's website Find all posts by this user Quote this message in a reply
iGame3D
Moderator
***


Posts: 231
Group: Moderators
Joined: Apr 2007
Status: Offline
Reputation: 0
Post: #5
RE: MurgaLua Compiler

Code:
-- path to compiled binary
pathToMurgaLua = string.gsub(murgaLua_ExePath,"(.*)/.*","%1")
appImage = pathToMurgaLua.."/background.gif"

-- will return correct path if cd to scripts path prior to running script
CurDirImage = lfs.currentdir() .."/background.gif"

fltk.fl_register_images()
-- if the file exists at same path as binary
if lfs.attributes(appImage) ~= nil then  img_back = Fl_Shared_Image.get(appImage) end

-- if the file exists at same path as script
if lfs.attributes(CurDirImage) ~= nil  then img_back = Fl_Shared_Image.get(CurDirImage) end


Using this I can get a script and/or its compiled version to find the image.
I'll try something similiar with the bezier example, it uses a subdirectory.
I don't understand require so I'll cheat it again.

-- Groovy, Bezier Example compiled with images

This post was last modified: 02-01-2008 08:19 AM by iGame3D.

02-01-2008 08:05 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Juergen
Member
***


Posts: 81
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #6
RE: MurgaLua Compiler

JohnMurga Wrote:
Embed it ... By using the new picture and hex functions to dump as a hex string, and then reload/decode it as hex string at runtime.


Ouch, I was asking myself, why you introduced those two functions. The functionality (base64 en/decoding) is already available in murgaLua and is actually superior.

Code:
if arg[1]==nil then print("You should provide a filename!") return 1 end
binary_name=io.open(arg[1],"rb")
if not binary_name then print("You should provide a valid filename!") return 1 end
print("Load and summing binary data")
binary_data=binary_name:read("*a")
binary_name:close()
binary_size=#binary_data
binary_md5sum=md5.sum(binary_data)
print("encoding, decoding and summing b64 data")
b64_string=(mime.b64(binary_data,nil))
b64_string_size=#b64_string
binary_data_b64=(mime.unb64(b64_string,nil))
binary_b64_md5sum=md5.sum(binary_data_b64)
binary_data_b64=nil
b64_string=nil
collectgarbage()
print("encoding, decoding and summing hex data")
hex_string=murgaLua.encodeDataAsHex(binary_data)
hex_string_size=#hex_string
binary_data_hex=murgaLua.decodeDataFromHex(hex_string)
binary_hex_md5sum=md5.sum(binary_data_hex)
hex_string=nil
binary_data_hex=nil
binary_data=nil
collectgarbage()
if binary_md5sum~=binary_b64_md5sum then print("Something is wrong with the b64 function!") return 1 end
if binary_md5sum~=binary_hex_md5sum then print("Something is wrong with the hex function!") return 1 end
print("The original file size was "..binary_size.." bytes long")
print(string.format("The b64 encoded data is %d bytes long, which is %.2f%% more than the original data",b64_string_size,b64_string_size/binary_size*100-100))
print(string.format("The hex encoded data is %d bytes long, which is %.2f%% more than the original data",hex_string_size,hex_string_size/binary_size*100-100))
print(string.format("The hex encoded string is %.2f%% bigger than the b64 encoded one",hex_string_size/b64_string_size*100-100))


If you test it with a big file you can see that the hex functions are also much slower.

I think it would be a good idea to either remove the two functions or to call mime de/encoding internally.

Juergen

02-01-2008 09:08 AM
Find all posts by this user Quote this message in a reply
JohnMurga
Administrator
*******


Posts: 381
Group: Administrators
Joined: Apr 2007
Status: Offline
Reputation: 2
Post: #7
RE: MurgaLua Compiler

Juergen Wrote:
Ouch, I was asking myself, why you introduced those two functions. The functionality (base64 en/decoding) is already available in murgaLua and is actually superior.


You are right in that embedding the image using base64 would be a MUCH better solution ... However, the hex functions where there for some hex conversions I needed to perform, so they where the first thing that sprung to mind.

They are slow because they are currently coded in Lua, I'll change that at a future date, however the functionality is useful :-)

Cheers
JohnM

02-01-2008 09:38 AM
Visit this user's website Find all posts by this user Quote this message in a reply
iGame3D
Moderator
***


Posts: 231
Group: Moderators
Joined: Apr 2007
Status: Offline
Reputation: 0
Post: #8
RE: MurgaLua Compiler

MurgaLua compiler is cool.

I took Marielle's old Applescript Bundle for running murgaLua with
an included script and modified so it only need run the new compiled binary.

I dropped any needed files or directories into "bundle.app/Contents/MacOS/"
where the compiled binary resides and everything is working like a charm.
Even mikshaws widget demo is running self contained.

Here's ten demo stand alone bundles for Mac OS X
The scripts for most of the demos are included, else they
are already in the released examples folder.

Oh this is whats inside "calculator, circledraw, console, photo_gallery, widgets, bezieranim, scripteditor, step7murgaLua, eventdetection, mondrian"

This post was last modified: 12-23-2013 05:37 PM by iGame3D.

02-01-2008 03:26 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Juergen
Member
***


Posts: 81
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #9
RE: MurgaLua Compiler

JohnMurga Wrote:
They are slow because they are currently coded in Lua, I'll change that at a future date, however the functionality is useful :-)


I guessed something like that already from the "stellar" performance ;-)

But I don't get it, why to bother to implement something like that in Lua when the C implementation is trivial and much simpler then the Lua implementation. BTW aren't Lua strings immutabe? Then this could bring noMMU system instantly down.

Juergen

P.S.: An example for a C implementation:

bin2hex:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv){
unsigned char byte;
char lookup[]="0123456789ABCDEF";

while (fread((char *) &byte,1,1,stdin)==1) {
printf("%c%c",lookup[(byte>>4)%16],lookup[byte%16]);
}
return 0;
}


hex2bin:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv){
unsigned char byte,i,j,obyte=0;
unsigned char lookup[]="0123456789ABCDEF";

j=0;
while (fread((char *) &byte,1,1,stdin)==1) {
  for(i=0;i<16;i++) {
    if (byte==lookup[i]) {
       obyte+=(j==0)?i<<4:i;
       if (j==1) {printf("%c",obyte); obyte=0;}
       j^=1;
       break;
     }
  }
}
return 0;
}

02-01-2008 09:08 PM
Find all posts by this user Quote this message in a reply
JohnMurga
Administrator
*******


Posts: 381
Group: Administrators
Joined: Apr 2007
Status: Offline
Reputation: 2
Post: #10
RE: MurgaLua Compiler

Juergen Wrote:
But I don't get it, why to bother to implement something like that in Lua when the C implementation is trivial and much simpler then the Lua implementation. BTW aren't Lua strings immutabe? Then this could bring noMMU system instantly down.


With some of these things I enjoy trying to write it in Lua ... And as it is I just knocked it as quickly as I could for simple 16 byte values, so it didn't matter much.

The Lua implementation is pretty trivial too :-)

PHP Code:
function decodeDataFromHex (myString)
    
local myFunction = function (someData)
        return 
base.string.char (base.tonumber(someData16 ))
    
end
    
return base.string.gsub(myString'(%x%x)'myFunction)
end

function encodeDataAsHex (myString)
    
local myFunction = function (someData)
        return (
'%02x'):format(someData:byte())
    
end
    
return base.string.gsub(myString'.'myFunction )
end 


But I'll change it to "C" for the next release.

Cheers
JohnM

This post was last modified: 02-01-2008 11:48 PM by JohnMurga.

02-01-2008 11:47 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Pages (2): « First [1] 2 Next > Last »
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: