lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I made some small test scripts to demonstrate the problem. I was
working on an app where the original coder used "if not pcall" to
check if a config file existed in the same directory or not. If not,
before the app loads, a config popup is supposed to appear so you can
set the default save path.

It used to work fine, but at some point during my update of it (which
involved learning to compile a new version) this stopped working. When
the pcall == false, it will no longer trigger anything, not even an
iup.Message, when I try to launch the app from it's .exe. If the
config file that it's looking for is there, then the app will start as
normal, otherwise it crashes at pcall.

When I try to compile, I get a warning that I don't understand:

Compiling "app.c"...
In file included from app.c:9:
app.c: In function 'main':
C:/MyLibs/lua-5.1/include/lauxlib.h:112:31: warning: value computed is
not used [-Wunused-value]
  112 |         (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
      |                               ^~
app.c:20:5: note: in expansion of macro 'luaL_dofile'
   20 |     luaL_dofile(L, "app.lua");
      |     ^~~~~~~~~~~
Linking executable "app.exe"...

I don't know what macro expansion is or what value isn't getting used
because luaL_dofile works and the initialization messages from Lua
scripts fire, but the .exe crashes at pcall.
The weird thing is, if I bypass the C file and just open the app's
main Lua script in the IupLua interpreter, the pcall works fine. How
do I fix my compiling problem?
Here are some sample scripts:

app.c
------------------------------------
#include <stdio.h>
#include <stdlib.h>

#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>

#include <iup.h>
#include <iuplua.h>

int main(int argc, char ** argv) {

    lua_State *L = luaL_newstate();
    luaL_openlibs(L);
    iuplua_open(L);

    luaL_dofile(L, "app.lua");

    IupClose();
    lua_close(L);
    return 0;
}


app.lua
-------------------------------------------
iup.Message("app.lua","App starting...")

dofile("managePrefs.lua")

if not pcall(dofile,"prefs.lua") then
    iup.Message("app.lua","pcall: fail\nprefs.lua not found")
    setPrefs()
else
    iup.Message("app.lua","pcall: success\nprefs.lua exists")
end


managePrefs.lua
--------------------------------------------------------------
iup.Message("managePrefs.lua","Preference Manager Initialized")

function setPrefs()
    iup.Message("managePrefs.lua","Here you would set preferences and
generate the prefs.lua file.")
end


prefs.lua
-------------------------------------------------------------
iup.Message("prefs.lua","Preferences Successfully Loaded.")