Changeset 74 for UI/ui_lua.cpp


Ignore:
Timestamp:
11/01/09 12:32:25 (4 years ago)
Author:
knowknowledge
Message:

Added Button Callbacks.
Buttons can take either Lua code or C++ function pointers.
From the Lua Console (`), use the command 'menu()' to see an example.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • UI/ui_lua.cpp

    r69 r74  
    7171int UI_Lua::newButton(lua_State *luaVM){ 
    7272        int n = lua_gettop(luaVM);  // Number of arguments 
    73         if (n != 6) 
    74                 return luaL_error(luaVM, "Got %d arguments expected 5 (class, x, y, w, h, caption)", n); 
     73        if ( (n != 6) && (n != 7) ) 
     74                return luaL_error(luaVM, "Got %d arguments expected 6 or 7 (class, x, y, w, h, caption [Lua_code])", n); 
    7575 
    7676        double x = luaL_checknumber (luaVM, 2); 
     
    7979        double h = luaL_checknumber (luaVM, 5); 
    8080        string caption = luaL_checkstring (luaVM, 6); 
     81        string code = ""; 
     82        if(n==7) code = luaL_checkstring (luaVM, 7); 
    8183 
    8284        // Allocate memory for a pointer to object 
    8385        Button **button= (Button**)lua_newuserdata(luaVM, sizeof(Button*)); 
    84         *button = new Button(x,y,w,h,caption); 
     86        *button = new Button(x,y,w,h,caption,code); 
    8587 
    8688        // Note: We're not putting this button anywhere! 
Note: See TracChangeset for help on using the changeset viewer.