Murga-Projects Forums

Full Version: [WIP] MurgaLua Reference Tool
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

mikshaw Wrote:
Change the "external_viewer" variable to the text editor of your choice.

This thing gets better every minute.

Beta 2 is now available. This version doesn't have many changes, but I particularly wanted to fix that edit preview problem as soon as possible. It now uses a separate instance of murgaLua (using murgaLua_ExePath), and includes the global variables that are used in some of the widget demos. This of course won't work in murgaLua prior to 0.6, but with an earlier version the user can still export script changes and/or edit in the external editor. By the time the beta stage has passed I'll have rewritten the menu system anyway, so support for 0.5.5 will have to be dropped.
I knew I should have posted my changes as I went along.
Everytime I edit this thing, you come out with a new version.

In order for the compiled and/or script version to run equally
I changed the code last night to this

-- set directory separator according to operating system
if murgaLua.getHostOsName() == "windows" then demo_sep="\\" else demo_sep="/" end

--default to current directory, works after cd in scripting, not in standalone
CurDir = lfs.currentdir().."/"

-- find murgalua folder, or the script as compiled binary
pathToMurgaLua = string.gsub(murgaLua_ExePath,"(.*)/.*","%1").."/"

-- test for presence of demo scripts folder
if lfs.attributes(pathToMurgaLua.."script") ~= nil then CurDir = pathToMurgaLua end

-- in script mode the argument is received when executing this script
if arg[0] ~= nil then CurDir = arg[0] end  

-- Get the dirname and basename of the current script or binary
if string.find(CurDir,demo_sep) then
  demo_appdir=string.gsub(CurDir,"(.*)"..demo_sep..".*","%1") -- data directory

arg throws an error in the compiled version unless it gets some data.
My changes manage to kill this bug.

/bin/murgaLua/examples/widgets: [string "--#!/bin/murgaLua..."]:236: attempt to index global 'arg' (a nil value)
stack traceback:
        [string "--#!/bin/murgaLua..."]:236: in function 'newFunc'
        [string "murgaLua"]:268: in function 'decompileMurgaLua'
        [string ""]:1: in main chunk
        [C]: ?

Also have to comment out "#!/bin/murgaLua" in the first line for compile.
It will throw a false error at line 268 for some reason.

I just made the code changes and recompiled it works on my side at least.
See what happens over there.

I'll make this permanent in the future. Thanks.

Also have to comment out "#!/bin/murgaLua" in the first line for compile

I couldn't say why, unless maybe the interpreter is checked against murgaLua_ExePath or something?
I'm going to continue using it in the releases, though (should be easy enough to remove before compiling). It's just my preference to make scripts executable and run them directly, and is common practice in Unix/Linux. Using a script as an argument to an interpreter is an unnecessary pain in my butt.

It looks like it needs more work to be used in both script and binary format. The arg={} line breaks the script...arg[0] no longer works after that, and therefore all paths are searched for in the current directory. That's definitely NOT acceptable...I need it to find the proper demo_appdir no matter what the current directory is, and I'm not going to force a change of directory in order to do this. Also, if arg[0] doesn't work in the binary there are at least two other places it needs fixing, in demo_menu_callback() and demo_show_readme().

mikshaw Wrote:
Also, if arg[0] doesn't work in the binary there are at least two other places it needs fixing, in demo_menu_callback() and demo_show_readme().

Yep the read me and "Show main script code" breaks with the change of arg.

arg breaks the script when trying it from a dofile()

I could send the binary an argument, but the argument
is based on the script, which isn't needed once the binary is built.
Lets see what that does.

I don't understand why the arg table doesn't work in the binary, since it's standard Lua. Perhaps there is a problem with the compiler.

Before starting to run the script, lua collects all arguments in the command line in a global table called arg. The script name is stored at index 0, the first argument after the script name goes to index 1, and so on. Any arguments before the script name (that is, the interpreter name plus the options) go to negative indices. For instance, in the call

$ lua -la b.lua t1 t2

the interpreter first runs the file a.lua, then creates a table

arg = { [-2] = "lua", [-1] = "-la",
[0] = "b.lua",
[1] = "t1", [2] = "t2" }

and finally runs the file b.lua. The script is called with arg[1], arg[2], as arguments; it can also access these arguments with the vararg expression '...'.

The compiled version doesn't get any arguments since it doesn't require an external script, arg will be nil unless the binary itself is sent an argument.

Sending the binary an argument of the original script does the trick.
No need to change any of the code I mentioned earlier.
Except that first line.
I'm looking forward to seeing what you might find, but if there is no available pointer to the path of the executable I don't intend to support the binary version of this package. I'm not going to rely on the user being in the application directory.

EDIT: Okies, then. I spoke too soon. When you say "sending an argument" do you mean sending it when you compile, or the enduser sending an argument to the compiled package?
The Applescript script that launches the executable sends the argument.

Its an applescript bundle with the murgaLua compiled binary "widgets" in a directory thus:

The content of your widget stuff, images, scripts, etc is thrown into

When the program bundle is double clicked it activates the following script,
which cd's to the bundle directory and launches the widgets binary with the
widgets.lua script acting as argument.

set murgaBinary to "Contents/MacOS/widgets"
set luascript to "Contents/Resources/lua/widgets.lua"
set bundlepath to path to me as string
-- cd and launch binary
set s to "cd '" & the POSIX path of bundlepath & "'; " & murgaBinary & " " & luascript
do shell script (s)

It could work with just a murgaLua executable instead of the compiled widgets binary,
which is how I ran it a long time ago, but this was a test of the compile process.

The benefit: no install, no authorization, no chmod, no command line
Just unzip + double click = widgets!

Pages: 1 2 3 4 5 6 7 8 9 10 11
Reference URL's