lua/deployer.cpp
Go to the documentation of this file.
1 /*
2  * Lua-RTT bindings: Lua module for creating a deployer.
3  *
4  * (C) Copyright 2010 Markus Klotzbuecher
5  * markus.klotzbuecher@mech.kuleuven.be
6  * Department of Mechanical Engineering,
7  * Katholieke Universiteit Leuven, Belgium.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public
11  * License as published by the Free Software Foundation;
12  * version 2 of the License.
13  *
14  * As a special exception, you may use this file as part of a free
15  * software library without restriction. Specifically, if other files
16  * instantiate templates or use macros or inline functions from this
17  * file, or you compile this file and link it with other files to
18  * produce an executable, this file does not by itself cause the
19  * resulting executable to be covered by the GNU General Public
20  * License. This exception does not however invalidate any other
21  * reasons why the executable file might be covered by the GNU General
22  * Public License.
23  *
24  * This library is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27  * Lesser General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public
30  * License along with this library; if not, write to the Free Software
31  * Foundation, Inc., 59 Temple Place,
32  * Suite 330, Boston, MA 02111-1307 USA
33  */
34 
35 extern "C" {
36 #include <lua.h>
37 #include <lauxlib.h>
38 #include <lualib.h>
39 
40 #include <string.h>
41 }
42 
43 #include <rtt/TaskContext.hpp>
44 #include <ocl/OCL.hpp>
46 
47 using namespace std;
48 using namespace OCL;
49 using namespace Orocos;
50 
51 /* template for generating GC function */
52 template<typename T>
54 {
55  reinterpret_cast<T*>(lua_touserdata(L, 1))->~T();
56  return 0;
57 }
58 
59 /*
60  * Deployer
61  */
62 static int deployer_new(lua_State *L)
63 {
64  const char *s;
65  std::string str;
66 
67  s = luaL_checkstring(L, 1);
68  str = s;
70  TaskContext** tc = (TaskContext**) lua_newuserdata(L, sizeof(TaskContext*));
71 
72  *tc = (TaskContext*) d;
73  luaL_getmetatable(L, "TaskContext");
74  lua_setmetatable(L, -2);
75  return 1;
76 }
77 
78 /* only explicit destrutction of deployers */
79 static const struct luaL_Reg DeploymentComponent_f [] = {
80  {"new", deployer_new },
81  {NULL, NULL}
82 };
83 
84 static const struct luaL_Reg DeploymentComponent_m [] = {
85  /* {"__gc", deployer_gc }, */
86  {NULL, NULL}
87 };
88 
89 extern "C" {
91 {
92  /* register MyObj
93  * 1. line creates metatable MyObj and registers name in registry
94  * 2. line duplicates metatable
95  * 3. line sets metatable[__index]=metatable
96  * 4. line register methods in metatable
97  * 5. line registers free functions in global mystuff.MyObj table
98  */
99  luaL_newmetatable(L, "TaskContext");
100  lua_pushvalue(L, -1); /* duplicates metatable */
101  lua_setfield(L, -2, "__index");
102  luaL_register(L, NULL, DeploymentComponent_m);
103  luaL_register(L, "deployer", DeploymentComponent_f);
104 
105  return 1;
106 }
107 } /* extern "C" */
LUA_API void() lua_setfield(lua_State *L, int idx, const char *k)
LUA_API void() lua_pushvalue(lua_State *L, int idx)
LUA_API void *() lua_newuserdata(lua_State *L, size_t sz)
int GCMethod(lua_State *L)
LUA_API int() lua_setmetatable(lua_State *L, int objindex)
struct lua_State lua_State
Definition: lua-repl.h:54
static int deployer_new(lua_State *L)
static const struct luaL_Reg DeploymentComponent_m[]
LUA_API void *() lua_touserdata(lua_State *L, int idx)
int luaopen_deployer(lua_State *L)
static const struct luaL_Reg DeploymentComponent_f[]


ocl
Author(s): OCL Development Team
autogenerated on Wed Jun 26 2019 19:26:27