deployer.cpp
Go to the documentation of this file.
00001 /*
00002  * Lua-RTT bindings: Lua module for creating a deployer.
00003  *
00004  * (C) Copyright 2010 Markus Klotzbuecher
00005  * markus.klotzbuecher@mech.kuleuven.be
00006  * Department of Mechanical Engineering,
00007  * Katholieke Universiteit Leuven, Belgium.
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU General Public
00011  * License as published by the Free Software Foundation;
00012  * version 2 of the License.
00013  *
00014  * As a special exception, you may use this file as part of a free
00015  * software library without restriction.  Specifically, if other files
00016  * instantiate templates or use macros or inline functions from this
00017  * file, or you compile this file and link it with other files to
00018  * produce an executable, this file does not by itself cause the
00019  * resulting executable to be covered by the GNU General Public
00020  * License.  This exception does not however invalidate any other
00021  * reasons why the executable file might be covered by the GNU General
00022  * Public License.
00023  *
00024  * This library is distributed in the hope that it will be useful,
00025  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00026  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00027  * Lesser General Public License for more details.
00028  *
00029  * You should have received a copy of the GNU General Public
00030  * License along with this library; if not, write to the Free Software
00031  * Foundation, Inc., 59 Temple Place,
00032  * Suite 330, Boston, MA  02111-1307  USA
00033  */
00034 
00035 extern "C" {
00036 #include <lua.h>
00037 #include <lauxlib.h>
00038 #include <lualib.h>
00039 
00040 #include <string.h>
00041 }
00042 
00043 #include <rtt/TaskContext.hpp>
00044 #include <ocl/OCL.hpp>
00045 #include <deployment/DeploymentComponent.hpp>
00046 
00047 using namespace std;
00048 using namespace OCL;
00049 using namespace Orocos;
00050 
00051 /* template for generating GC function */
00052 template<typename T>
00053 int GCMethod(lua_State* L)
00054 {
00055         reinterpret_cast<T*>(lua_touserdata(L, 1))->~T();
00056         return 0;
00057 }
00058 
00059 /*
00060  * Deployer
00061  */
00062 static int deployer_new(lua_State *L)
00063 {
00064         const char *s;
00065         std::string str;
00066 
00067         s = luaL_checkstring(L, 1);
00068         str = s;
00069         DeploymentComponent *d = new DeploymentComponent(str);
00070         TaskContext** tc = (TaskContext**) lua_newuserdata(L, sizeof(TaskContext*));
00071 
00072         *tc = (TaskContext*) d;
00073         luaL_getmetatable(L, "TaskContext");
00074         lua_setmetatable(L, -2);
00075         return 1;
00076 }
00077 
00078 /* only explicit destrutction of deployers */
00079 static const struct luaL_Reg DeploymentComponent_f [] = {
00080         {"new", deployer_new },
00081         {NULL, NULL}
00082 };
00083 
00084 static const struct luaL_Reg DeploymentComponent_m [] = {
00085         /* {"__gc", deployer_gc }, */
00086         {NULL, NULL}
00087 };
00088 
00089 extern "C" {
00090 int luaopen_deployer(lua_State *L)
00091 {
00092         /* register MyObj
00093          * 1. line creates metatable MyObj and registers name in registry
00094          * 2. line duplicates metatable
00095          * 3. line sets metatable[__index]=metatable
00096          * 4. line register methods in metatable
00097          * 5. line registers free functions in global mystuff.MyObj table
00098          */
00099         luaL_newmetatable(L, "TaskContext");
00100         lua_pushvalue(L, -1);                   /* duplicates metatable */
00101         lua_setfield(L, -2, "__index");
00102         luaL_register(L, NULL, DeploymentComponent_m);
00103         luaL_register(L, "deployer", DeploymentComponent_f);
00104 
00105         return 1;
00106 }
00107 } /* extern "C" */


ocl
Author(s): OCL Development Team
autogenerated on Mon Oct 6 2014 03:16:36