2011-12-05 12 views
6

की मैं एक सी कार्यक्रम में लुआ एम्बेड करने का यह एक साधारण परीक्षण लिख रहा हूँ।अंतर्निहित घोषणा luaL_openlibs

मैं Windows/Mingw और लिनक्स पर एक ही मुद्दा है।

gcc -Wall -o test_lua lua_test.c -I/usr/include/lua5.1 -llua5.1 

विंडोज़ पर:

gcc -Wall -o test_lua.exe lua_test.c -llua5.1 

दोनों मामले मैं निम्न चेतावनी है में: यहाँ जीसीसी आदेश मैं लिनक्स पर उपयोग करें

warning: implicit declaration of function 
       'luaL_openlibs' [-Wimplicit-function-declaration] 

कार्यक्रम काम करता है लेकिन शायद मैं इसमें किसी भी मानक लुआ libs का उपयोग न करें? मुझे यह चेतावनी क्यों मिलती है? मैं luaL_openLibslauxlib.h में परिभाषा देखता हूं!

#include <lua.h> 
#include <lauxlib.h> 
#include <stdlib.h> 
#include <stdio.h> 

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

    int status; 
    lua_State *L; 

    L = luaL_newstate(); 

    // Init lua 
    luaL_openlibs(L); 

    // Load script 
    status = luaL_loadfile(L,"lua_test.lua"); 
    if (status) { 
    fprintf(stderr,"Couldn't load file\n"); 
    exit(1); 
    } 

    // Push data 
    lua_pushnumber(L, 5000); 
    lua_setglobal(L, "clife"); 
    lua_pushnumber(L, 6000); 
    lua_setglobal(L, "ttime"); 
    lua_pushnumber(L, 3000); 
    lua_setglobal(L, "atime"); 

    // Run script 
    int result = lua_pcall(L, 0, LUA_MULTRET, 0); 
    if (result) { 
    fprintf(stderr,"Failed to run script: %s\n", lua_tostring(L,-1)); 
    exit(1); 
    } 

    // Value at top of the stack is the result 
    const char *schedule = lua_tostring(L,-1); 

    fprintf(stdout,"Computed schedule is: %s\n", schedule); 

    // Close lua 
    lua_pop(L, 1); 
    lua_close(L); 

    return 0; 

} 

यहाँ लुआ हिस्सा है::

यहाँ सी हिस्सा है

io.write("lua_test.lua -- will generate schedule\n") 

io.write("Wizard life is " .. clife .. "\n") 

schedule = "" 
ctime = ttime - atime 
if clife > 4500 then 
    schedule = schedule .. "[" .. ctime .. ",p]" 
    schedule = schedule .. "[" .. ctime+500 .. ",a]" 
    schedule = schedule .. "[" .. ctime+1000 .. ",i]" 
    schedule = schedule .. "[" .. ctime+1500 .. ",n]\n" 
else 
    schedule = schedule .. "[" .. ctime .. ",d]" 
    schedule = schedule .. "[" .. ctime+500 .. ",r]" 
    schedule = schedule .. "[" .. ctime+1000 .. ",a]" 
    schedule = schedule .. "[" .. ctime+1500 .. ",i]" 
    schedule = schedule .. "[" .. ctime+1500 .. ",n]\n" 
end 

io.write("Returning " .. schedule .. "\n"); 

return schedule 

उत्तर

10
AFAIK & मेरी 5.1.4 स्थापना में

समारोह lualib.h में रहता है, lauxlib.h नहीं

+0

अपने अंतिम विश्राम स्थल प्रतीत होता है; यह 5.3 है और यह अभी भी सच है। – Qix

2

luaL_openlibs ifdef ब्लॉक में परिभाषित हो सकता है।

प्रीप्रोसेसिंग के बाद स्रोत प्राप्त करने के लिए जीसीसी के साथ -E का उपयोग करें। पाइप। ग्रेप।

संबंधित मुद्दे