Lua Scripting Integration

  • 46 Replies
  • 22251 Views
*

Offline Velo

  • *
  • 30
Re: Lua Scripting Integration
« Reply #30 on: 11 / May / 2008, 13:39:01 »
Advertisements
I was thinking of not putting anything but scripts to the chdk/scripts folder. If (when) the path is hardcoded to chdk/scripts, would it be possible to load libs from e.g. chdk/lib? I think I tried
require "../lib/libname"
but no avail.

Hmm. Haven't tried it. But my guess would be that it should work. Seems like its unfortunately not the case.


*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: Lua Scripting Integration
« Reply #31 on: 11 / May / 2008, 14:13:49 »
I would prefer the scripts folder to only have scripts and user created subfolders, because everything in chdk/scripts will result in more keypresses required in script selection.

I also think there should be a standard default absolute search path for the scripts (like chdk/lualib), so that a script wouldn't stop working if I move it around a bit. Otherwise (to use a library in several scripts) I'd need to either make multiple copies of libraries or edit scripts each time I move them.

But you all knew this already, keep up the good work. :)

*

Offline Jucifer

  • *****
  • 251
  • [A710IS]
Re: Lua Scripting Integration
« Reply #32 on: 11 / May / 2008, 14:23:03 »
What if libs were first searched from one location (chdk/lualib), and then if not found, from another (chdk/scripts)? Or the other way round...

Is this correct?

Code: (c) [Select]
static int loader_Lua (lua_State *L) {
  const char *filename;
  const char *name = luaL_checkstring(L, 1);
  lua_pushstring(L, "A/CHDK/LUALIB/");
  lua_pushvalue(L, 1);
  lua_pushstring(L, ".LUA");
  lua_concat(L, 3);
  filename = lua_tostring(L, -1);
  if (!readable(filename)) {
    lua_pushstring(L, "A/CHDK/SCRIPTS/");
    lua_pushvalue(L, 1);
    lua_pushstring(L, ".LUA");
    lua_concat(L, 3);
    filename = lua_tostring(L, -1);
    }
  if (!readable(filename))
    return 0;
  if (luaL_loadfile(L, filename) != 0)
    loaderror(L, filename);
  return 1;  /* library loaded successfully */
}

At least it works. :]
« Last Edit: 11 / May / 2008, 14:38:55 by Jucifer »

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: Lua Scripting Integration
« Reply #33 on: 11 / May / 2008, 14:46:47 »
What if libs were first searched from one location (chdk/lualib), and then if not found, from another (chdk/scripts)? Or the other way round...

Probably better the other way around i.e. a local copy in chdk/scripts would override the system default library in chdk/lualib. Altough...I can already foresee multiple search paths causing apparent user errors such as

Q: "I installed your new version of the yaddayadda Lua library but it didn't fetch my morning paper nor did it brew coffee like you promised it would!"
A: "Do you have old copies hanging around somewhere?"
Q: "No, I don't."
A: "Are you sure?"
Q: "Ooooooohhhh sorry never mind..."

But I can live with either.  :haha


*

Offline Jucifer

  • *****
  • 251
  • [A710IS]
Re: Lua Scripting Integration
« Reply #34 on: 11 / May / 2008, 14:54:01 »
Ok, now they're the other way around. Building. I'll update my evil build tonight.

*

Offline fe50

  • ******
  • 3094
  • IXUS50 & 860, SX10 Star WARs-Star RAWs
    • fe50
Re: Lua Scripting Integration
« Reply #35 on: 04 / July / 2008, 07:20:01 »
Just for information to all the people want's to do lua scripting:

I've started a wikia page for lua, and - surprise- you'll find it by name LUA  8)

You're all welcome to participate !

*

Offline reyalp

  • ******
  • 11583
Re: Lua Scripting Integration
« Reply #36 on: 22 / July / 2008, 21:54:03 »
On my camera (a540, using my own build of Jucifers branch), the script console disappears right away if there is a compile error. Since this happens before the script runs, turning on print screen won't help.

A quick workaround in lua is to do something like this:
Code: [Select]
function saferun(code)
local status
local f,msg=loadstring(code,"code")
if not f then
print("compile err")
print(msg)
sleep(5000)
else
print("compile ok")
sleep(2000)
status,msg = pcall(f)
if not status then
print("run err")
print(msg)
sleep(5000)
end
end
end
-- now put all your code in a big string
saferun([[
all
my
lua code
]])
You can of course stick the saferun function in a module.

The sleeps keep the console up long enough to see what happened.

That said, I think I'll buckle down and write a lua test harness that works on the PC, because pulling the card, rebooting the camera and trying to read the error off the tiny screen gets old real quick 8)

I also got the lua string library working, but it's a bit messy with the required bits of libc hacked in here and there.
Don't forget what the H stands for.

*

Offline fe50

  • ******
  • 3094
  • IXUS50 & 860, SX10 Star WARs-Star RAWs
    • fe50
Re: Lua Scripting Integration
« Reply #37 on: 23 / July / 2008, 03:42:14 »
Hi reyalp,
there's the uBasic script debugger by zeno, written in Java, posted here - perhaps parts from this may be helpful for you...


*

Offline zeno

  • *****
  • 884
Re: Lua Scripting Integration
« Reply #38 on: 23 / July / 2008, 04:30:39 »
My debugger doesn't support Lua. It probably could, but from a quick look at the Lua code, it  doesn't look easy.
A570, S100, Ixus 127
Author of ASSIST, STICK, WASP, ACID, SDMInst, LICKS, WICKS, MacBoot, UBDB, CFGEdit

*

Offline fe50

  • ******
  • 3094
  • IXUS50 & 860, SX10 Star WARs-Star RAWs
    • fe50
Re: Lua Scripting Integration
« Reply #39 on: 23 / July / 2008, 05:20:56 »
Hi zeno,
thx, i gave this hint as a little inspiration to reyalp, perhaps he can reuse some code parts like the GUI or other things to save some time in his project...

Your debugger is a nice tool, very helpful with big basic scripts !

 

Related Topics