lua-users home
lua-l archive

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


Hi all,
       Can some give me step by step procedure to debug the lua script using Decoda editor.


I did as below, but not able to debug. Please suggest me.

Lua_Test.cpp
#include "stdafx.h"
#include <windows.h>
extern "C" {
    #include "lua.h"
    #include "lualib.h"
    #include "lauxlib.h"
}

/* the Lua interpreter */
lua_State* L;



static int average(lua_State *L)
{
    /* get number of arguments */
    int n = lua_gettop(L);
    double sum = 0;
    int i;

    /* loop through each argument */
    for (i = 1; i <= n; i++)
    {
        /* total the arguments */
        sum += lua_tonumber(L, i);
    }

    printf("Sum = %f\n", sum);
    /* push the average */
    lua_pushnumber(L, sum / n);

    /* push the sum */
    lua_pushnumber(L, sum);

    /* return the number of results */
    return 2;
}





int _tmain(int argc, _TCHAR* argv[])
{
    /* initialize Lua */
    L = lua_open();

    /* load Lua base libraries */
    luaL_openlibs(L);

    /* register our function */
    lua_register(L, "average", average);

    /* run the script */
    luaL_dofile(L, "avg.lua");

    /* cleanup Lua */
    lua_close(L);

    /* pause */
    printf( "Press enter to exit..." );
    getchar();

    return 0;

}


avg.lua:

--Find the average
avg, sum = average(10, 20, 30, 40, 50)

print("The average is ", avg)
print("The sum is ", sum)




Decoda Project Settings:





Breakpoint in avg.lua using Decoda:



Thanks & Regards,
Muqtheear.S