Lua implementation help - General Discussion and Assistance - CHDK Forum supplierdeeply

Lua implementation help

  • 3 Replies
  • 1971 Views
*

Offline RaduP

  • *****
  • 890
Lua implementation help
« on: 12 / October / 2009, 05:55:40 »
Advertisements
I am loosing my mind with Lua.
We have this function:

Code: [Select]
static int os_remove (lua_State *L) {
  const char *filename = luaL_checkstring(L, 1);
  return os_pushresult(L, remove(filename) == 0, filename);
}

Now, does it call

Code: [Select]
int remove(const char *name) {
    return _Remove(name);
}

in /platform/generic/wrappers.c ?
Because I have debug code both before and after return os_pushresult(L, remove(filename) == 0, filename); and that debug code is triggered. I have debug code in int remove(const char *name), and that is not triggered (and as a bonus, the camera crashes).
Any idea WTF is going on here?

*

Offline RaduP

  • *****
  • 890
Re: Lua implementation help
« Reply #1 on: 12 / October / 2009, 14:40:12 »
Ok, this is really, really f^&*ed up.

I have the following 2 functions in wrappers.c:
Code: [Select]
int remove(const char *name) {
blink_led(3);
    return _Remove(name);
}

int remove_test(const char *name) {
blink_led(3);
    return _Remove(name);
}

As you can see, they are identical except for the name.

Now I modified os_remove() like this:
Code: [Select]
static int os_remove (lua_State *L) {
  int pula;
  const char *filename = luaL_checkstring(L, 1);
  pula=os_pushresult(L, remove(filename) == 0, filename);
  blink_led(2);
  return pula;

}

If I have:   pula=os_pushresult(L, remove(filename) == 0, filename); then the LED blinks only 2 times (so remove wasn't even called).
If I have:   pula=os_pushresult(L, remove_test(filename) == 0, filename); then the LED blinks 3 times then 2 times.

So WTF is wrong, this drives me crazy.

*

Offline RaduP

  • *****
  • 890
Re: Lua implementation help
« Reply #2 on: 12 / October / 2009, 15:00:55 »
Even stranger, calling remove() instead of remove_test() does remove the file, but no blinking.. So is there some internal function called remove() or something in LUA? I couldn't find anything like that, but at this time nothing makes sense.

*

Offline RaduP

  • *****
  • 890
Re: Lua implementation help
« Reply #3 on: 12 / October / 2009, 15:18:09 »
Ok, mystery solved...
in stdlib.h

#ifdef FS_USE_FUT
#define mkdir(x) MakeDirectory_Fut(x)
#define rename(x,y) RenameFile_Fut(x,y)
#define remove(x) DeleteFile_Fut(x)
#endif

that was really, really devious.. Especially because that is ONLY used in Lua:
Lua's Makefile
CFLAGS+=$(CTHUMB) -DFS_USE_FUT


 

Related Topics