11#include < dbStaticLib.h>
2- #include < epicsExport.h>
32#include < iocsh.h>
3+ #include < epicsExport.h>
44#include " luaEpics.h"
55
66int l_setfield (lua_State* state)
77{
88 DBENTRY * entry = dbAllocEntry (*iocshPpdbbase);
9-
9+
1010 lua_getfield (state, 1 , " name" );
1111 const char * record_name = lua_tostring (state, -1 );
1212 lua_pop (state, 1 );
13-
13+
1414 lua_pushnil (state);
15-
15+
1616 while (lua_next (state, 2 ))
1717 {
1818 lua_pushvalue (state, -2 );
1919 const char * field_name = lua_tostring (state, -1 );
2020 const char * val = lua_tostring (state, -2 );
2121 lua_pop (state, 2 );
22-
22+
2323 if (dbFindRecord (entry, record_name))
2424 {
2525 dbFreeEntry (entry);
2626 luaL_error (state, " Unable to find record: %s\n " , record_name);
2727 }
28-
28+
2929 if (dbFindField (entry, field_name))
3030 {
3131 dbFreeEntry (entry);
3232 luaL_error (state, " Unable to find %s field for record: %s\n " , field_name, record_name);
3333 }
34-
34+
3535 if (dbPutString (entry, val))
3636 {
3737 dbFreeEntry (entry);
3838 luaL_error (state, " Error setting %s field on record %s to %s\n " , field_name, record_name, val);
3939 }
4040 }
41-
41+
4242 dbFreeEntry (entry);
4343 return 0 ;
4444}
@@ -49,35 +49,35 @@ int l_record(lua_State* state)
4949
5050 const char * type = luaL_checkstring (state, 1 );
5151 const char * name = luaL_checkstring (state, 2 );
52-
52+
5353 if (! iocshPpdbbase) { luaL_error (state, " No database definition found.\n " ); }
54-
54+
5555 DBENTRY * entry = dbAllocEntry (*iocshPpdbbase);
56-
56+
5757 int status = dbFindRecordType (entry, type);
58-
58+
5959 if (status)
60- {
60+ {
6161 dbFreeEntry (entry);
6262 luaL_error (state, " Error (%d) finding record type: %s\n " , status, type);
6363 }
64-
64+
6565 status = dbCreateRecord (entry, name);
66-
66+
6767 if (status)
6868 {
6969 dbFreeEntry (entry);
7070 luaL_error (state, " Error (%d) creating record: %s\n " , status, name);
7171 }
72-
72+
7373 dbFreeEntry (entry);
74-
74+
7575 lua_newtable (state);
7676 lua_pushstring (state, name);
7777 lua_setfield (state, -2 , " name" );
78-
78+
7979 luaL_setmetatable (state, " rec_meta" );
80-
80+
8181 return 1 ;
8282}
8383
@@ -89,11 +89,11 @@ int luaopen_database (lua_State *L)
8989 {" __call" , l_setfield},
9090 {NULL , NULL }
9191 };
92-
92+
9393 luaL_newmetatable (L, " rec_meta" );
9494 luaL_setfuncs (L, rec_meta, 0 );
9595 lua_pop (L, 1 );
96-
96+
9797 static const luaL_Reg mylib[] = {
9898 {" record" , l_record},
9999 {NULL , NULL } /* sentinel */
0 commit comments