Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7962 in orxonox.OLD


Ignore:
Timestamp:
May 29, 2006, 9:42:29 PM (18 years ago)
Author:
snellen
Message:

Works… well almost

Location:
branches/script_engine/src/lib/script_engine
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/script_engine/src/lib/script_engine/Makefile.am

    r7829 r7962  
    22INCLUDES= -I../../../extern_libs
    33
    4 #noinst_LIBRARIES = libORXscript.a
     4noinst_LIBRARIES = libORXscript.a
    55
    6 #libORXscript_a_SOURCES =
     6libORXscript_a_SOURCES =
    77
    88AM_CPPFLAGS= @LUA_INCLUDES@
  • branches/script_engine/src/lib/script_engine/account.cc

    r7821 r7962  
    11    #include "luaincl.h"
     2    #include <iostream>
    23
    34    #include "lunar.h"
     
    2930
    3031
     32    class Object {
     33      public:
     34        static const char className[];
     35        static Lunar<Object>::RegType methods[];
     36
     37        Object(lua_State* L) { }
     38        ~Object() { printf("deleted Object (%p)\n", this); }
     39
     40        int printName(lua_State* L){std::cout<<"Hi i'm object!"<<std::endl; return 0;}
     41    };
     42
     43    const char Object::className[] = "Object";
     44
     45    Lunar<Object>::RegType Object::methods[] = {
     46      method(Object, printName),
     47      {0,0}
     48    };
     49
    3150    int main(int argc, char *argv[])
    3251    {
     
    4160
    4261      Lunar<Account>::Register(L);
     62      Lunar<Object>::Register(L);
     63      Object obj(L);
     64      Lunar<Object>::insertObject(L,&obj,"Object",false);
     65
     66
     67
    4368
    4469      if(argc>1) lua_dofile(L, argv[1]);
  • branches/script_engine/src/lib/script_engine/lunar.h

    r7821 r7962  
    1     #include "luaincl.h"
     1#include <string>
     2
     3
     4#include "luaincl.h"
     5
    26
    37    template <typename T> class Lunar {
     
    109113      }
    110114
     115
     116      static int insertObject(lua_State* L, T* obj, const std::string& name, bool gc=false)
     117      {
     118        int objectRef = push(L, obj, gc);
     119
     120        lua_pushliteral(L, name.c_str() );
     121        lua_pushvalue(L, objectRef );
     122        lua_settable(L, LUA_GLOBALSINDEX );
     123
     124        return objectRef;
     125      }
     126
    111127      // get userdata from Lua stack and return pointer to T object
    112128      static T *check(lua_State *L, int narg) {
  • branches/script_engine/src/lib/script_engine/lunartest.lua

    r7829 r7962  
    44  printf("Account balance = $%0.02f\n", self:balance())
    55end
     6
     7--o = Object()
     8Object:printName()
    69
    710a = Account(100)
Note: See TracChangeset for help on using the changeset viewer.