CVS commit: src/lib/lua/libm

2022-11-23 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Nov 23 18:15:43 UTC 2022

Modified Files:
src/lib/lua/libm: libm.c

Log Message:
fix vax build


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/lua/libm/libm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/lua/libm

2022-11-23 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Nov 23 18:15:43 UTC 2022

Modified Files:
src/lib/lua/libm: libm.c

Log Message:
fix vax build


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/lua/libm/libm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/lua/libm/libm.c
diff -u src/lib/lua/libm/libm.c:1.1 src/lib/lua/libm/libm.c:1.2
--- src/lib/lua/libm/libm.c:1.1	Mon Nov 21 17:01:33 2022
+++ src/lib/lua/libm/libm.c	Wed Nov 23 13:15:43 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: libm.c,v 1.1 2022/11/21 22:01:33 christos Exp $	*/
+/* $NetBSD: libm.c,v 1.2 2022/11/23 18:15:43 christos Exp $	*/
 
 /*-
  * Copyright (c) 2022 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: libm.c,v 1.1 2022/11/21 22:01:33 christos Exp $");
+__RCSID("$NetBSD: libm.c,v 1.2 2022/11/23 18:15:43 christos Exp $");
 
 #include 
 #include 
@@ -140,7 +140,9 @@ DFUNC_DBL(lgamma)
 DFUNC_DBL(log)
 DFUNC_DBL(log10)
 DFUNC_DBL(log1p)
+#ifndef __vax__
 DFUNC_DBL_DBL(nextafter)
+#endif
 DFUNC_DBL_DBL(pow)
 DFUNC_DBL_DBL(remainder)
 DFUNC_DBL(rint)
@@ -277,7 +279,9 @@ static const struct luaL_Reg lualibm[] =
 	{ "log10", libm_log10 },
 	{ "log1p", libm_log1p },
 	{ "nan", libm_nan },
+#ifndef __vax__
 	{ "nextafter", libm_nextafter },
+#endif
 	{ "pow", libm_pow },
 	{ "remainder", libm_remainder },
 	{ "rint", libm_rint },



CVS commit: src/lib/lua/libm

2022-11-22 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Tue Nov 22 15:41:05 UTC 2022

Modified Files:
src/lib/lua/libm: Makefile

Log Message:
Correct path for libm.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/lua/libm/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/lua/libm/Makefile
diff -u src/lib/lua/libm/Makefile:1.1 src/lib/lua/libm/Makefile:1.2
--- src/lib/lua/libm/Makefile:1.1	Mon Nov 21 22:01:33 2022
+++ src/lib/lua/libm/Makefile	Tue Nov 22 15:41:04 2022
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.1 2022/11/21 22:01:33 christos Exp $
+# $NetBSD: Makefile,v 1.2 2022/11/22 15:41:04 rin Exp $
 
 LUA_MODULES = libm
 LUA_SRCS.libm   = libm.c
-LUA_DPLIBS += m /usr/lib
+LUA_DPLIBS += m ${.CURDIR}/../../libm
 
 .include 



CVS commit: src/lib/lua/libm

2022-11-22 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Tue Nov 22 15:41:05 UTC 2022

Modified Files:
src/lib/lua/libm: Makefile

Log Message:
Correct path for libm.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/lua/libm/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/lua/sqlite

2019-05-16 Thread Travis Paul
Module Name:src
Committed By:   tpaul
Date:   Thu May 16 12:42:35 UTC 2019

Modified Files:
src/lib/lua/sqlite: sqlite.c

Log Message:
Prevent Lua from crashing if clear_bindings() is called on a statement
that failed to prepare().

ok mbalmer@


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/lua/sqlite/sqlite.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/lua/sqlite

2019-05-16 Thread Travis Paul
Module Name:src
Committed By:   tpaul
Date:   Thu May 16 12:42:35 UTC 2019

Modified Files:
src/lib/lua/sqlite: sqlite.c

Log Message:
Prevent Lua from crashing if clear_bindings() is called on a statement
that failed to prepare().

ok mbalmer@


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/lua/sqlite/sqlite.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/lua/sqlite/sqlite.c
diff -u src/lib/lua/sqlite/sqlite.c:1.9 src/lib/lua/sqlite/sqlite.c:1.10
--- src/lib/lua/sqlite/sqlite.c:1.9	Wed May 10 07:36:01 2017
+++ src/lib/lua/sqlite/sqlite.c	Thu May 16 12:42:35 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sqlite.c,v 1.9 2017/05/10 07:36:01 mbalmer Exp $ */
+/*	$NetBSD: sqlite.c,v 1.10 2019/05/16 12:42:35 tpaul Exp $ */
 
 /*
  * Copyright (c) 2011, 2013, 2016, 2017 Marc Balmer 
@@ -336,7 +336,10 @@ stmt_clear_bindings(lua_State *L)
 	sqlite3_stmt **stmt;
 
 	stmt = luaL_checkudata(L, 1, SQLITE_STMT_METATABLE);
-	sqlite3_clear_bindings(*stmt);
+	if (*stmt) {
+		sqlite3_clear_bindings(*stmt);
+		*stmt = NULL;
+	}
 	return 0;
 }
 



CVS commit: src/lib/lua/sqlite

2017-05-10 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Wed May 10 07:36:01 UTC 2017

Modified Files:
src/lib/lua/sqlite: sqlite.c

Log Message:
Guard against double freeing of objects (explicit by the Lua program, then
later by the garbage collector).
This fixes PR bin/52218.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/lib/lua/sqlite/sqlite.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/lua/sqlite/sqlite.c
diff -u src/lib/lua/sqlite/sqlite.c:1.8 src/lib/lua/sqlite/sqlite.c:1.9
--- src/lib/lua/sqlite/sqlite.c:1.8	Mon Feb 15 15:56:33 2016
+++ src/lib/lua/sqlite/sqlite.c	Wed May 10 07:36:01 2017
@@ -1,7 +1,7 @@
-/*	$NetBSD: sqlite.c,v 1.8 2016/02/15 15:56:33 mbalmer Exp $ */
+/*	$NetBSD: sqlite.c,v 1.9 2017/05/10 07:36:01 mbalmer Exp $ */
 
 /*
- * Copyright (c) 2011, 2013, 2016 Marc Balmer 
+ * Copyright (c) 2011, 2013, 2016, 2017 Marc Balmer 
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -120,7 +120,11 @@ db_close(lua_State *L)
 	sqlite3 **db;
 
 	db = luaL_checkudata(L, 1, SQLITE_DB_METATABLE);
-	lua_pushinteger(L, sqlite3_close(*db));
+	if (*db) {
+		lua_pushinteger(L, sqlite3_close(*db));
+		*db = NULL;
+	} else
+		lua_pushnil(L);
 	return 1;
 
 }
@@ -342,7 +346,10 @@ stmt_finalize(lua_State *L)
 	sqlite3_stmt **stmt;
 
 	stmt = luaL_checkudata(L, 1, SQLITE_STMT_METATABLE);
-	sqlite3_finalize(*stmt);
+	if (*stmt) {
+		sqlite3_finalize(*stmt);
+		*stmt = NULL;
+	}
 	return 0;
 }
 



CVS commit: src/lib/lua/sqlite

2017-05-10 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Wed May 10 07:36:01 UTC 2017

Modified Files:
src/lib/lua/sqlite: sqlite.c

Log Message:
Guard against double freeing of objects (explicit by the Lua program, then
later by the garbage collector).
This fixes PR bin/52218.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/lib/lua/sqlite/sqlite.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/lua/sqlite

2016-02-15 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Mon Feb 15 15:56:33 UTC 2016

Modified Files:
src/lib/lua/sqlite: sqlite.c

Log Message:
Fix function name, no functional change.
Found by Travis Paul, (see PR/50786), thanks for reporting!


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/lua/sqlite/sqlite.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/lua/sqlite

2016-02-15 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Mon Feb 15 15:56:33 UTC 2016

Modified Files:
src/lib/lua/sqlite: sqlite.c

Log Message:
Fix function name, no functional change.
Found by Travis Paul, (see PR/50786), thanks for reporting!


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/lua/sqlite/sqlite.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/lua/sqlite/sqlite.c
diff -u src/lib/lua/sqlite/sqlite.c:1.7 src/lib/lua/sqlite/sqlite.c:1.8
--- src/lib/lua/sqlite/sqlite.c:1.7	Sat Jul 19 18:38:34 2014
+++ src/lib/lua/sqlite/sqlite.c	Mon Feb 15 15:56:33 2016
@@ -1,7 +1,7 @@
-/*	$NetBSD: sqlite.c,v 1.7 2014/07/19 18:38:34 lneto Exp $ */
+/*	$NetBSD: sqlite.c,v 1.8 2016/02/15 15:56:33 mbalmer Exp $ */
 
 /*
- * Copyright (c) 2011, 2013 Marc Balmer 
+ * Copyright (c) 2011, 2013, 2016 Marc Balmer 
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -392,7 +392,7 @@ static const struct constant sqlite_cons
 };
 
 static void
-gpio_set_info(lua_State *L)
+sqlite_set_info(lua_State *L)
 {
 	lua_pushliteral(L, "_COPYRIGHT");
 	lua_pushliteral(L, "Copyright (C) 2011, 2012, 2013 by "
@@ -449,7 +449,7 @@ luaopen_sqlite(lua_State* L)
 	luaL_newlib(L, sqlite_methods);
 	luaL_setfuncs(L, db_methods, 0);
 	luaL_setfuncs(L, stmt_methods, 0);
-	gpio_set_info(L);
+	sqlite_set_info(L);
 
 	/* The database connection metatable */
 	if (luaL_newmetatable(L, SQLITE_DB_METATABLE)) {



Re: CVS commit: src/lib/lua/syslog

2013-11-12 Thread Christos Zoulas
In article 20131112143203.8cd3...@cvs.netbsd.org,
Marc Balmer source-changes-d@NetBSD.org wrote:
-=-=-=-=-=-

Module Name:   src
Committed By:  mbalmer
Date:  Tue Nov 12 14:32:03 UTC 2013

Added Files:
   src/lib/lua/syslog: Makefile syslog.c

Log Message:
Add a syslog(3) binding for Lua (not yet linked to the build.)

Is there any reason not to use the modern syslog (thread-safe) functions
openlog_r(), syslog_r(), syslogp_r()?

christos



Re: CVS commit: src/lib/lua/syslog

2013-11-12 Thread Marc Balmer
Am 12.11.13 17:04, schrieb Christos Zoulas:
 In article 20131112143203.8cd3...@cvs.netbsd.org,
 Marc Balmer source-changes-d@NetBSD.org wrote:
 -=-=-=-=-=-

 Module Name: src
 Committed By:mbalmer
 Date:Tue Nov 12 14:32:03 UTC 2013

 Added Files:
  src/lib/lua/syslog: Makefile syslog.c

 Log Message:
 Add a syslog(3) binding for Lua (not yet linked to the build.)
 
 Is there any reason not to use the modern syslog (thread-safe) functions
 openlog_r(), syslog_r(), syslogp_r()?

Good question.  We would have to keep the context somewhere (certainly
solvable), then, I wonder I Lua is ever used threaded?  Could the
problem arise in reality (it did not in our stuff since Jan 1st 2009)

Maybe if two threads create separate states, and then both threads use
syslog at the same time?  (can not happen at this moment).




Re: CVS commit: src/lib/lua/syslog

2013-11-12 Thread Justin Cormack
On Tue, Nov 12, 2013 at 4:29 PM, Marc Balmer m...@msys.ch wrote:
 Am 12.11.13 17:04, schrieb Christos Zoulas:
 In article 20131112143203.8cd3...@cvs.netbsd.org,
 Marc Balmer source-changes-d@NetBSD.org wrote:
 -=-=-=-=-=-

 Module Name: src
 Committed By:mbalmer
 Date:Tue Nov 12 14:32:03 UTC 2013

 Added Files:
  src/lib/lua/syslog: Makefile syslog.c

 Log Message:
 Add a syslog(3) binding for Lua (not yet linked to the build.)

 Is there any reason not to use the modern syslog (thread-safe) functions
 openlog_r(), syslog_r(), syslogp_r()?

 Good question.  We would have to keep the context somewhere (certainly
 solvable), then, I wonder I Lua is ever used threaded?  Could the
 problem arise in reality (it did not in our stuff since Jan 1st 2009)

 Maybe if two threads create separate states, and then both threads use
 syslog at the same time?  (can not happen at this moment).

People do use it threaded sometimes. I would just return a userdata
with a _gc method to the user.

Justin


Re: CVS commit: src/lib/lua/syslog

2013-11-12 Thread Christos Zoulas
On Nov 12,  5:29pm, m...@msys.ch (Marc Balmer) wrote:
-- Subject: Re: CVS commit: src/lib/lua/syslog

| Good question.  We would have to keep the context somewhere (certainly
| solvable), then, I wonder I Lua is ever used threaded?  Could the
| problem arise in reality (it did not in our stuff since Jan 1st 2009)
| 
| Maybe if two threads create separate states, and then both threads use
| syslog at the same time?  (can not happen at this moment).

If lua is never threaded then this is a non-issue...

christos


CVS commit: src/lib/lua/syslog

2013-11-12 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Tue Nov 12 14:32:03 UTC 2013

Added Files:
src/lib/lua/syslog: Makefile syslog.c

Log Message:
Add a syslog(3) binding for Lua (not yet linked to the build.)


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/lib/lua/syslog/Makefile \
src/lib/lua/syslog/syslog.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/lib/lua/syslog/Makefile
diff -u /dev/null src/lib/lua/syslog/Makefile:1.1
--- /dev/null	Tue Nov 12 14:32:03 2013
+++ src/lib/lua/syslog/Makefile	Tue Nov 12 14:32:03 2013
@@ -0,0 +1,6 @@
+#	$NetBSD: Makefile,v 1.1 2013/11/12 14:32:03 mbalmer Exp $
+
+LUA_MODULES=		syslog
+LUA_SRCS.syslog=	syslog.c
+
+.include bsd.lua.mk
Index: src/lib/lua/syslog/syslog.c
diff -u /dev/null src/lib/lua/syslog/syslog.c:1.1
--- /dev/null	Tue Nov 12 14:32:03 2013
+++ src/lib/lua/syslog/syslog.c	Tue Nov 12 14:32:03 2013
@@ -0,0 +1,165 @@
+/*	$NetBSD: syslog.c,v 1.1 2013/11/12 14:32:03 mbalmer Exp $ */
+
+/*
+ * Copyright (c) 2013 Marc Balmer m...@msys.ch
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* Lua binding for syslog */
+
+#include sys/types.h
+
+#include errno.h
+#include lua.h
+#include lauxlib.h
+#include stdlib.h
+#include syslog.h
+#include unistd.h
+
+int luaopen_syslog(lua_State *);
+
+static int
+syslog_openlog(lua_State *L)
+{
+	const char *ident;
+	int option;
+	int facility;
+
+	ident = luaL_checkstring(L, 1);
+	option = luaL_checkinteger(L, 2);
+	facility = luaL_checkinteger(L, 3);
+	openlog(ident, option, facility);
+	return 0;
+}
+
+static int
+syslog_syslog(lua_State *L)
+{
+	syslog(luaL_checkint(L, 1), %s, luaL_checkstring(L, 2));
+	return 0;
+}
+
+static int
+syslog_closelog(lua_State *L)
+{
+	closelog();
+	return 0;
+}
+
+static int
+syslog_setlogmask(lua_State *L)
+{
+	lua_pushinteger(L, setlogmask(luaL_checkint(L, 1)));
+	return 1;
+}
+
+static void
+syslog_set_info(lua_State *L)
+{
+	lua_pushliteral(L, _COPYRIGHT);
+	lua_pushliteral(L, Copyright (C) 2013 by 
+	Marc Balmer m...@msys.ch);
+	lua_settable(L, -3);
+	lua_pushliteral(L, _DESCRIPTION);
+	lua_pushliteral(L, syslog binding for Lua);
+	lua_settable(L, -3);
+	lua_pushliteral(L, _VERSION);
+	lua_pushliteral(L, syslog 1.0.0);
+	lua_settable(L, -3);
+}
+
+struct constant {
+	const char *name;
+	int value;
+};
+
+#define CONSTANT(NAME)		{ #NAME, NAME }
+
+static struct constant syslog_constant[] = {
+	/* syslog options */
+	CONSTANT(LOG_CONS),
+	CONSTANT(LOG_NDELAY),
+	CONSTANT(LOG_NOWAIT),
+	CONSTANT(LOG_ODELAY),
+	CONSTANT(LOG_PERROR),
+	CONSTANT(LOG_PID),
+
+	/* syslog facilities */
+	CONSTANT(LOG_AUTH),
+	CONSTANT(LOG_AUTHPRIV),
+	CONSTANT(LOG_CRON),
+	CONSTANT(LOG_DAEMON),
+	CONSTANT(LOG_FTP),
+	CONSTANT(LOG_KERN),
+	CONSTANT(LOG_LOCAL0),
+	CONSTANT(LOG_LOCAL1),
+	CONSTANT(LOG_LOCAL2),
+	CONSTANT(LOG_LOCAL3),
+	CONSTANT(LOG_LOCAL4),
+	CONSTANT(LOG_LOCAL5),
+	CONSTANT(LOG_LOCAL6),
+	CONSTANT(LOG_LOCAL7),
+	CONSTANT(LOG_LPR),
+	CONSTANT(LOG_MAIL),
+	CONSTANT(LOG_NEWS),
+	CONSTANT(LOG_SYSLOG),
+	CONSTANT(LOG_USER),
+	CONSTANT(LOG_UUCP),
+
+	/* syslog levels */
+	CONSTANT(LOG_EMERG),
+	CONSTANT(LOG_ALERT),
+	CONSTANT(LOG_CRIT),
+	CONSTANT(LOG_ERR),
+	CONSTANT(LOG_WARNING),
+	CONSTANT(LOG_NOTICE),
+	CONSTANT(LOG_INFO),
+	CONSTANT(LOG_DEBUG),
+
+	{ NULL, 0 }
+};
+
+int
+luaopen_syslog(lua_State *L)
+{
+	int n;
+	struct luaL_Reg luasyslog[] = {
+		{ openlog,	syslog_openlog },
+		{ syslog,	syslog_syslog },
+		{ closelog,	syslog_closelog },
+		{ setlogmask,	syslog_setlogmask },
+		{ NULL, NULL }
+	};
+
+#if LUA_VERSION_NUM = 502
+	luaL_newlib(L, luasyslog);
+#else
+	luaL_register(L, syslog, luasyslog);
+#endif
+	syslog_set_info(L);
+	for (n 

CVS commit: src/lib/lua/syslog

2013-11-12 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Tue Nov 12 14:32:03 UTC 2013

Added Files:
src/lib/lua/syslog: Makefile syslog.c

Log Message:
Add a syslog(3) binding for Lua (not yet linked to the build.)


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/lib/lua/syslog/Makefile \
src/lib/lua/syslog/syslog.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/lua/sqlite

2013-10-27 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sun Oct 27 12:38:08 UTC 2013

Modified Files:
src/lib/lua/sqlite: sqlite.c

Log Message:
More user friendly sqlite.open() function.
Add a few more symbols.
Register all function in the sqlite table.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/lua/sqlite/sqlite.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/lua/sqlite/sqlite.c
diff -u src/lib/lua/sqlite/sqlite.c:1.5 src/lib/lua/sqlite/sqlite.c:1.6
--- src/lib/lua/sqlite/sqlite.c:1.5	Fri Nov  2 12:24:52 2012
+++ src/lib/lua/sqlite/sqlite.c	Sun Oct 27 12:38:08 2013
@@ -1,7 +1,7 @@
-/*	$NetBSD: sqlite.c,v 1.5 2012/11/02 12:24:52 mbalmer Exp $ */
+/*	$NetBSD: sqlite.c,v 1.6 2013/10/27 12:38:08 mbalmer Exp $ */
 
 /*
- * Copyright (c) 2011 Marc Balmer m...@msys.ch
+ * Copyright (c) 2011, 2013 Marc Balmer m...@msys.ch
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -81,11 +81,14 @@ sqlite_open(lua_State *L)
 	sqlite3 **db;
 
 	db = lua_newuserdata(L, sizeof(sqlite3 *));
-	lua_pushinteger(L, sqlite3_open_v2(luaL_checkstring(L, -3), db,
-	(int)luaL_checkinteger(L, -2), NULL));
-
 	luaL_getmetatable(L, SQLITE_DB_METATABLE);
-	lua_setmetatable(L, -3);
+	lua_setmetatable(L, -2);
+
+	if (lua_gettop(L)  2)
+		lua_pushinteger(L, sqlite3_open_v2(luaL_checkstring(L, -3), db,
+		(int)luaL_checkinteger(L, -2), NULL));
+	else
+		lua_pushinteger(L, sqlite3_open(luaL_checkstring(L, -2), db));
 	return 2;
 
 }
@@ -362,8 +365,10 @@ static const struct constant sqlite_cons
 	{ INTERRUPT,		SQLITE_INTERRUPT },
 	{ IOERR,		SQLITE_IOERR },
 	{ CORRUPT,		SQLITE_CORRUPT },
+	{ NOTFOUND,		SQLITE_NOTFOUND },
 	{ FULL,		SQLITE_FULL },
 	{ CANTOPEN,		SQLITE_CANTOPEN },
+	{ PROTOCOL,		SQLITE_PROTOCOL },
 	{ EMPTY,		SQLITE_EMPTY },
 	{ SCHEMA,		SQLITE_SCHEMA },
 	{ TOOBIG,		SQLITE_TOOBIG },
@@ -375,14 +380,13 @@ static const struct constant sqlite_cons
 	{ FORMAT,		SQLITE_FORMAT },
 	{ RANGE,		SQLITE_RANGE },
 	{ NOTADB,		SQLITE_NOTADB },
-
 	{ ROW,		SQLITE_ROW },
 	{ DONE,		SQLITE_DONE },
 
 	/* File modes */
 	{ OPEN_READONLY,	SQLITE_OPEN_READONLY },
 	{ OPEN_READWRITE,	SQLITE_OPEN_READWRITE },
-	{ OPEN_CREATE,	SQLITE_OPEN_CREATE },
+	{ OPEN_CREATE,	SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE },
 
 	{ NULL,			0 }
 };
@@ -391,14 +395,14 @@ static void
 gpio_set_info(lua_State *L)
 {
 	lua_pushliteral(L, _COPYRIGHT);
-	lua_pushliteral(L, Copyright (C) 2011, 2012 by 
+	lua_pushliteral(L, Copyright (C) 2011, 2012, 2013 by 
 	Marc Balmer m...@msys.ch);
 	lua_settable(L, -3);
 	lua_pushliteral(L, _DESCRIPTION);
 	lua_pushliteral(L, SQLite interface for Lua);
 	lua_settable(L, -3);
 	lua_pushliteral(L, _VERSION);
-	lua_pushliteral(L, sqlite 1.0.2);
+	lua_pushliteral(L, sqlite 1.0.3);
 	lua_settable(L, -3);
 }
 
@@ -443,6 +447,8 @@ luaopen_sqlite(lua_State* L)
 	sqlite3_initialize();
 
 	luaL_register(L, sqlite, sqlite_methods);
+	luaL_register(L, NULL, db_methods);
+	luaL_register(L, NULL, stmt_methods);
 	gpio_set_info(L);
 
 	/* The database connection metatable */



CVS commit: src/lib/lua/sqlite

2013-10-27 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sun Oct 27 12:38:08 UTC 2013

Modified Files:
src/lib/lua/sqlite: sqlite.c

Log Message:
More user friendly sqlite.open() function.
Add a few more symbols.
Register all function in the sqlite table.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/lua/sqlite/sqlite.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/lua/gpio

2013-10-26 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sat Oct 26 09:18:00 UTC 2013

Modified Files:
src/lib/lua/gpio: gpio.c

Log Message:
also register gpio_methods on the gpio table


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/lua/gpio/gpio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/lua/gpio/gpio.c
diff -u src/lib/lua/gpio/gpio.c:1.7 src/lib/lua/gpio/gpio.c:1.8
--- src/lib/lua/gpio/gpio.c:1.7	Thu Mar 15 02:02:21 2012
+++ src/lib/lua/gpio/gpio.c	Sat Oct 26 09:18:00 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: gpio.c,v 1.7 2012/03/15 02:02:21 joerg Exp $ */
+/*	$NetBSD: gpio.c,v 1.8 2013/10/26 09:18:00 mbalmer Exp $ */
 
 /*
  * Copyright (c) 2011 Marc Balmer m...@msys.ch
@@ -255,13 +255,14 @@ static void
 gpio_set_info(lua_State *L)
 {
 	lua_pushliteral(L, _COPYRIGHT);
-	lua_pushliteral(L, Copyright (C) 2011 Marc Balmer m...@msys.ch);
+	lua_pushliteral(L, Copyright (C) 2011, 2013 Marc Balmer 
+	m...@msys.ch);
 	lua_settable(L, -3);
 	lua_pushliteral(L, _DESCRIPTION);
 	lua_pushliteral(L, GPIO interface for Lua);
 	lua_settable(L, -3);
 	lua_pushliteral(L, _VERSION);
-	lua_pushliteral(L, gpio 1.0.1);
+	lua_pushliteral(L, gpio 1.0.2);
 	lua_settable(L, -3);
 }
 
@@ -288,6 +289,7 @@ luaopen_gpio(lua_State* L)
 	int n;
 
 	luaL_register(L, gpio, methods);
+	luaL_register(L, NULL, gpio_methods);
 	gpio_set_info(L);
 
 	/* The gpio metatable */



CVS commit: src/lib/lua/gpio

2013-10-26 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sat Oct 26 09:18:00 UTC 2013

Modified Files:
src/lib/lua/gpio: gpio.c

Log Message:
also register gpio_methods on the gpio table


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/lua/gpio/gpio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/lua/sqlite

2012-11-02 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Fri Nov  2 12:24:52 UTC 2012

Modified Files:
src/lib/lua/sqlite: sqlite.c

Log Message:
- Update to the version on github.com.
- Fix stmt_bind(): SQLite makes a copy of the string passed (which can be
  garbage collected).  Problem found by Kubo Takehiro.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/lua/sqlite/sqlite.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/lua/sqlite/sqlite.c
diff -u src/lib/lua/sqlite/sqlite.c:1.4 src/lib/lua/sqlite/sqlite.c:1.5
--- src/lib/lua/sqlite/sqlite.c:1.4	Thu Mar 15 02:02:21 2012
+++ src/lib/lua/sqlite/sqlite.c	Fri Nov  2 12:24:52 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: sqlite.c,v 1.4 2012/03/15 02:02:21 joerg Exp $ */
+/*	$NetBSD: sqlite.c,v 1.5 2012/11/02 12:24:52 mbalmer Exp $ */
 
 /*
  * Copyright (c) 2011 Marc Balmer m...@msys.ch
@@ -207,7 +207,7 @@ stmt_bind(lua_State *L)
 		break;
 	case LUA_TSTRING:
 		lua_pushinteger(L, sqlite3_bind_text(*stmt, pidx,
-		lua_tostring(L, 3), -1, NULL));
+		lua_tostring(L, 3), -1, SQLITE_TRANSIENT));
 		break;
 	case LUA_TNIL:
 		lua_pushinteger(L, sqlite3_bind_null(*stmt, pidx));
@@ -391,13 +391,14 @@ static void
 gpio_set_info(lua_State *L)
 {
 	lua_pushliteral(L, _COPYRIGHT);
-	lua_pushliteral(L, Copyright (C) 2011 Marc Balmer m...@msys.ch);
+	lua_pushliteral(L, Copyright (C) 2011, 2012 by 
+	Marc Balmer m...@msys.ch);
 	lua_settable(L, -3);
 	lua_pushliteral(L, _DESCRIPTION);
 	lua_pushliteral(L, SQLite interface for Lua);
 	lua_settable(L, -3);
 	lua_pushliteral(L, _VERSION);
-	lua_pushliteral(L, sqlite 1.0.0);
+	lua_pushliteral(L, sqlite 1.0.2);
 	lua_settable(L, -3);
 }
 
@@ -405,36 +406,36 @@ int
 luaopen_sqlite(lua_State* L)
 {
 	static const struct luaL_Reg sqlite_methods[] = {
-		{ initialize,		sqlite_initialize },
-		{ shutdown,		sqlite_shutdown },
-		{ open,		sqlite_open },
-		{ libversion,		sqlite_libversion },
-		{ libversion_number,	sqlite_libversion_number },
-		{ sourceid,		sqlite_sourceid },
-		{ NULL,			NULL }
+		{ initialize,			sqlite_initialize },
+		{ shutdown,			sqlite_shutdown },
+		{ open,			sqlite_open },
+		{ libversion,			sqlite_libversion },
+		{ libversion_number,		sqlite_libversion_number },
+		{ sourceid,			sqlite_sourceid },
+		{ NULL,NULL }
 	};
 	static const struct luaL_Reg db_methods[] = {
-		{ close,		db_close },
-		{ prepare,		db_prepare },
-		{ exec,		db_exec },
-		{ errcode,		db_errcode },
-		{ errmsg,		db_errmsg },
-		{ get_autocommit,	db_get_autocommit },
-		{ changes,		db_changes },
-		{ NULL,			NULL }
+		{ close,			db_close },
+		{ prepare,			db_prepare },
+		{ exec,			db_exec },
+		{ errcode,			db_errcode },
+		{ errmsg,			db_errmsg },
+		{ get_autocommit,		db_get_autocommit },
+		{ changes,			db_changes },
+		{ NULL,NULL }
 	};
 	static const struct luaL_Reg stmt_methods[] = {
-		{ bind,		stmt_bind },
+		{ bind,			stmt_bind },
 		{ bind_parameter_count,	stmt_bind_parameter_count },
 		{ bind_parameter_index,	stmt_bind_parameter_index },
 		{ bind_parameter_name,	stmt_bind_parameter_name },
-		{ step,		stmt_step },
-		{ column,		stmt_column },
-		{ reset,		stmt_reset },
-		{ clear_bindings,	stmt_clear_bindings },
-		{ finalize,		stmt_finalize },
-		{ column_name,	stmt_column_name },
-		{ column_count,	stmt_column_count },
+		{ step,			stmt_step },
+		{ column,			stmt_column },
+		{ reset,			stmt_reset },
+		{ clear_bindings,		stmt_clear_bindings },
+		{ finalize,			stmt_finalize },
+		{ column_name,		stmt_column_name },
+		{ column_count,		stmt_column_count },
 		{ NULL,		NULL }
 	};
 	int n;



CVS commit: src/lib/lua/sqlite

2012-11-02 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Fri Nov  2 12:24:52 UTC 2012

Modified Files:
src/lib/lua/sqlite: sqlite.c

Log Message:
- Update to the version on github.com.
- Fix stmt_bind(): SQLite makes a copy of the string passed (which can be
  garbage collected).  Problem found by Kubo Takehiro.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/lua/sqlite/sqlite.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/lua/sqlite

2012-03-03 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sat Mar  3 11:32:14 UTC 2012

Modified Files:
src/lib/lua/sqlite: Makefile

Log Message:
Add an empty line.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/lua/sqlite/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/lua/sqlite/Makefile
diff -u src/lib/lua/sqlite/Makefile:1.2 src/lib/lua/sqlite/Makefile:1.3
--- src/lib/lua/sqlite/Makefile:1.2	Sun Oct 16 00:45:54 2011
+++ src/lib/lua/sqlite/Makefile	Sat Mar  3 11:32:14 2012
@@ -1,8 +1,9 @@
-#	$NetBSD: Makefile,v 1.2 2011/10/16 00:45:54 mbalmer Exp $
+#	$NetBSD: Makefile,v 1.3 2012/03/03 11:32:14 mbalmer Exp $
 
 LUA_MODULES=		sqlite
 LUA_SRCS.sqlite=	sqlite.c
 
 LUA_DPLIBS+=		sqlite3 \
 			${.CURDIR}/../../../external/public-domain/sqlite/lib
+
 .include bsd.lua.mk



CVS commit: src/lib/lua/sqlite

2012-03-03 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sat Mar  3 11:32:14 UTC 2012

Modified Files:
src/lib/lua/sqlite: Makefile

Log Message:
Add an empty line.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/lua/sqlite/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/lua/gpio

2011-11-13 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sun Nov 13 09:46:11 UTC 2011

Modified Files:
src/lib/lua/gpio: gpio.c

Log Message:
Start numbering pions with 0, not 1.  Ruined a demo, so it was a bad idea.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/lua/gpio/gpio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/lua/gpio/gpio.c
diff -u src/lib/lua/gpio/gpio.c:1.3 src/lib/lua/gpio/gpio.c:1.4
--- src/lib/lua/gpio/gpio.c:1.3	Mon Oct 10 20:41:05 2011
+++ src/lib/lua/gpio/gpio.c	Sun Nov 13 09:46:11 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: gpio.c,v 1.3 2011/10/10 20:41:05 christos Exp $ */
+/*	$NetBSD: gpio.c,v 1.4 2011/11/13 09:46:11 mbalmer Exp $ */
 
 /*
  * Copyright (c) 2011 Marc Balmer m...@msys.ch
@@ -112,7 +112,7 @@ gpio_get_pin(lua_State *L, int n, struct
 {
 	switch (lua_type(L, n)) {
 	case LUA_TNUMBER:
-		req-gp_pin = (int)lua_tointeger(L, n) - 1;	/* 1 based! */
+		req-gp_pin = (int)lua_tointeger(L, n);	/* not 1 based! */
 		break;
 	case LUA_TSTRING:
 		strlcpy(req-gp_name, lua_tostring(L, n), sizeof(req-gp_name));



CVS commit: src/lib/lua/gpio

2011-11-13 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sun Nov 13 13:37:25 UTC 2011

Modified Files:
src/lib/lua/gpio: gpio.c

Log Message:
Remove software pulsing.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/lua/gpio/gpio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/lua/gpio/gpio.c
diff -u src/lib/lua/gpio/gpio.c:1.4 src/lib/lua/gpio/gpio.c:1.5
--- src/lib/lua/gpio/gpio.c:1.4	Sun Nov 13 09:46:11 2011
+++ src/lib/lua/gpio/gpio.c	Sun Nov 13 13:37:24 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: gpio.c,v 1.4 2011/11/13 09:46:11 mbalmer Exp $ */
+/*	$NetBSD: gpio.c,v 1.5 2011/11/13 13:37:24 mbalmer Exp $ */
 
 /*
  * Copyright (c) 2011 Marc Balmer m...@msys.ch
@@ -224,56 +224,6 @@ gpio_attach(lua_State *L)
 	return 0;
 }
 
-static int
-gpio_pulse(lua_State *L)
-{
-	struct gpio_pulse pulse;
-	suseconds_t period, on, off, sec;
-	double freq, dc;
-	int *fd;
-
-	fd = luaL_checkudata(L, 1, GPIO_METATABLE);
-	freq = luaL_checknumber(L, 3);
-	dc = luaL_checknumber(L, 4);
-
-	if (freq  0.0 || (dc  0.0 || dc = 100.0))
-		gpio_error(L, %.f Hz, %.f%% duty cycle: invalid value,
-		freq, dc);
-
-	memset(pulse, 0, sizeof(pulse));
-	gpio_get_pin(L, 2, (void *)pulse);
-
-	if (freq  0.0  dc  0.0) {
-		period = 100 / freq;
-		on = period * dc / 100;
-		off = period - on;
-
-		if (on = 100) {
-			pulse.gp_pulse_on.tv_sec = sec = on / 100;
-			on -= sec * 100;
-			pulse.gp_pulse_on.tv_usec = on;
-		} else {
-			pulse.gp_pulse_on.tv_sec = 0;
-			pulse.gp_pulse_on.tv_usec = on;
-		}
-		if (off = 100) {
-			pulse.gp_pulse_off.tv_sec = sec = off / 100;
-			off -= sec * 100;
-			pulse.gp_pulse_off.tv_usec = off;
-		} else {
-			pulse.gp_pulse_off.tv_sec = 0;
-			pulse.gp_pulse_off.tv_usec = off;
-		}
-	} else {	/* gpio(4) defaults */
-		freq = 1.0;
-		dc = 50.0;
-	}
-
-	if (ioctl(*fd, GPIOPULSE, pulse) == -1)
-		gpio_error(L, GPIOPULSE);
-	return 0;
-}
-
 struct constant {
 	const char *name;
 	int value;
@@ -283,7 +233,6 @@ static const struct constant gpio_consta
 	/* GPIO pin states */
 	{ PIN_LOW,		GPIO_PIN_LOW },
 	{ PIN_HIGH,		GPIO_PIN_HIGH },
-	{ PIN_PULSE,		GPIO_PIN_PULSE },
 
 	/* GPIO pin configuration flags */
 	{ PIN_INPUT,		GPIO_PIN_INPUT },
@@ -314,7 +263,7 @@ gpio_set_info(lua_State *L)
 	lua_pushliteral(L, GPIO interface for Lua);
 	lua_settable(L, -3);
 	lua_pushliteral(L, _VERSION);
-	lua_pushliteral(L, gpio 1.0.0);
+	lua_pushliteral(L, gpio 1.0.1);
 	lua_settable(L, -3);
 }
 
@@ -336,7 +285,6 @@ luaopen_gpio(lua_State* L)
 		{ write,	gpio_write },
 		{ toggle,	gpio_toggle },
 		{ attach,	gpio_attach },
-		{ pulse,	gpio_pulse },
 		{ NULL,		NULL }
 	};
 	int n;



CVS commit: src/lib/lua/gpio

2011-11-13 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sun Nov 13 13:37:25 UTC 2011

Modified Files:
src/lib/lua/gpio: gpio.c

Log Message:
Remove software pulsing.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/lua/gpio/gpio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/lua

2011-11-07 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Tue Nov  8 01:52:06 UTC 2011

Modified Files:
src/lib/lua: Makefile

Log Message:
Check MKPIC and don't hard-code m68k.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/lua/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/lua/Makefile
diff -u src/lib/lua/Makefile:1.4 src/lib/lua/Makefile:1.5
--- src/lib/lua/Makefile:1.4	Sat Oct 15 10:46:24 2011
+++ src/lib/lua/Makefile	Tue Nov  8 01:52:05 2011
@@ -1,8 +1,8 @@
-#	$NetBSD: Makefile,v 1.4 2011/10/15 10:46:24 mbalmer Exp $
+#	$NetBSD: Makefile,v 1.5 2011/11/08 01:52:05 joerg Exp $
 
 .include bsd.own.mk
 
-.if ${MACHINE_ARCH} != m68000
+.if ${MKPIC} != no
 # No support for shared libraries and pic code.
 SUBDIR+=	gpio sqlite
 .endif



CVS commit: src/lib/lua

2011-11-07 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Tue Nov  8 01:52:06 UTC 2011

Modified Files:
src/lib/lua: Makefile

Log Message:
Check MKPIC and don't hard-code m68k.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/lua/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/lua/sqlite

2011-10-15 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sat Oct 15 10:26:30 UTC 2011

Added Files:
src/lib/lua/sqlite: Makefile sqlite.c

Log Message:
A Lua module to access SQLite databases.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/lib/lua/sqlite/Makefile \
src/lib/lua/sqlite/sqlite.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/lib/lua/sqlite/Makefile
diff -u /dev/null src/lib/lua/sqlite/Makefile:1.1
--- /dev/null	Sat Oct 15 10:26:30 2011
+++ src/lib/lua/sqlite/Makefile	Sat Oct 15 10:26:30 2011
@@ -0,0 +1,8 @@
+#	$NetBSD: Makefile,v 1.1 2011/10/15 10:26:30 mbalmer Exp $
+
+LUA_MODULES=		sqlite
+LUA_SRCS.sqlite=	sqlite.c
+
+LDADD+=			-lsqlite3
+
+.include bsd.lua.mk
Index: src/lib/lua/sqlite/sqlite.c
diff -u /dev/null src/lib/lua/sqlite/sqlite.c:1.1
--- /dev/null	Sat Oct 15 10:26:30 2011
+++ src/lib/lua/sqlite/sqlite.c	Sat Oct 15 10:26:30 2011
@@ -0,0 +1,481 @@
+/*	$NetBSD: sqlite.c,v 1.1 2011/10/15 10:26:30 mbalmer Exp $ */
+
+/*
+ * Copyright (c) 2011 Marc Balmer m...@msys.ch
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* SQLite interface for Lua */
+
+#include errno.h
+#include fcntl.h
+#include stdarg.h
+#include stdio.h
+#include string.h
+#include ctype.h
+#include stdlib.h
+#include sqlite3.h
+#include unistd.h
+
+#include lua.h
+#include lauxlib.h
+#include lualib.h
+
+#define SQLITE_DB_METATABLE SQLite database connection methods
+#define SQLITE_STMT_METATABLE SQLite statement methods
+
+int luaopen_sqlite(lua_State*);
+
+static void
+sqlite_error(lua_State *L, const char *fmt, ...)
+{
+	va_list ap;
+	int len;
+	char *msg;
+
+	va_start(ap, fmt);
+	len = vasprintf(msg, fmt, ap);
+	va_end(ap);
+
+	if (len != -1) {
+		lua_pushstring(L, msg);
+		free(msg);
+	} else
+		lua_pushstring(L, vasprintf failed);
+	lua_error(L);
+}
+
+static int
+sqlite_initialize(lua_State *L)
+{
+	lua_pushinteger(L, sqlite3_initialize());
+	return 1;
+}
+
+static int
+sqlite_shutdown(lua_State *L)
+{
+	lua_pushinteger(L, sqlite3_shutdown());
+	return 1;
+}
+
+static int
+sqlite_open(lua_State *L)
+{
+	sqlite3 **db;
+
+	db = lua_newuserdata(L, sizeof(sqlite3 *));
+	lua_pushinteger(L, sqlite3_open_v2(luaL_checkstring(L, -3), db,
+	(int)luaL_checkinteger(L, -2), NULL));
+
+	luaL_getmetatable(L, SQLITE_DB_METATABLE);
+	lua_setmetatable(L, -3);
+	return 2;
+
+}
+
+static int
+sqlite_libversion(lua_State *L)
+{
+	lua_pushstring(L, sqlite3_libversion());
+	return 1;
+}
+
+static int
+sqlite_libversion_number(lua_State *L)
+{
+	lua_pushinteger(L, sqlite3_libversion_number());
+	return 1;
+}
+
+static int
+sqlite_sourceid(lua_State *L)
+{
+	lua_pushstring(L, sqlite3_sourceid());
+	return 1;
+}
+
+static int
+db_close(lua_State *L)
+{
+	sqlite3 **db;
+
+	db = luaL_checkudata(L, 1, SQLITE_DB_METATABLE);
+	lua_pushinteger(L, sqlite3_close(*db));
+	return 1;
+
+}
+
+static int
+db_prepare(lua_State *L)
+{
+	sqlite3 **db;
+	sqlite3_stmt **stmt;
+	const char *sql;
+
+	db = luaL_checkudata(L, 1, SQLITE_DB_METATABLE);
+	stmt = lua_newuserdata(L, sizeof(sqlite3_stmt *));
+	sql = luaL_checkstring(L, 2);
+	lua_pushinteger(L, sqlite3_prepare_v2(*db, sql,
+	(int)strlen(sql) + 1, stmt, NULL));
+	luaL_getmetatable(L, SQLITE_STMT_METATABLE);
+	lua_setmetatable(L, -3);
+	return 2;
+
+}
+
+static int
+db_exec(lua_State *L)
+{
+	sqlite3 **db;
+
+	db = luaL_checkudata(L, 1, SQLITE_DB_METATABLE);
+	lua_pushinteger(L, sqlite3_exec(*db, lua_tostring(L, 2), NULL,
+	NULL, NULL));
+	return 1;
+}
+
+static int
+db_errcode(lua_State *L)
+{
+	sqlite3 **db;
+
+	db = luaL_checkudata(L, 1, SQLITE_DB_METATABLE);
+	lua_pushinteger(L, sqlite3_errcode(*db));
+	return 1;
+}
+
+static int

CVS commit: src/lib/lua/sqlite

2011-10-15 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sat Oct 15 10:27:06 UTC 2011

Added Files:
src/lib/lua/sqlite: test-sqlite.lua

Log Message:
A small test/demo program to show the sqlite Lua module usage.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/lib/lua/sqlite/test-sqlite.lua

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/lib/lua/sqlite/test-sqlite.lua
diff -u /dev/null src/lib/lua/sqlite/test-sqlite.lua:1.1
--- /dev/null	Sat Oct 15 10:27:06 2011
+++ src/lib/lua/sqlite/test-sqlite.lua	Sat Oct 15 10:27:06 2011
@@ -0,0 +1,53 @@
+require 'sqlite'
+
+print('initialize sqlite')
+sqlite.initialize()
+
+print('this is sqlite ' .. sqlite.libversion() .. ' (' ..
+sqlite.libversion_number() .. ')')
+print('sourceid ' .. sqlite.sourceid())
+
+db, state = sqlite.open('db.sqlite',
+sqlite.OPEN_READWRITE + sqlite.OPEN_CREATE)
+
+if state ~= sqlite.OK then
+	print('db open failed')
+else
+	err = db:exec('create table test (name varchar(32))')
+
+	if err ~= sqlite.OK then
+		print('table creation failed')
+		print('error code ' .. db:errcode() .. ' msg ' .. db:errmsg())
+	end
+
+	db:exec(insert into test values('Balmer'))
+
+	stmt = db:prepare(insert into test values(:name))
+
+	print('statement has ' .. stmt:bind_parameter_count() .. ' parameters')
+	print('param 1 name: ' .. stmt:bind_parameter_name(1))
+	print('param name is at index ' .. stmt:bind_parameter_index('name'))
+
+	stmt:bind(1, 'Hardmeier')
+	stmt:step()
+	stmt:reset()
+	stmt:bind(1, 'Keller')
+	stmt:step()
+	stmt:finalize()
+
+	s2 = db:prepare('select name from test')
+
+	while s2:step() == sqlite.ROW do
+		print('name = ' .. s2:column(1))
+	end
+	s2:finalize()
+
+	stmt = db:prepare('drop table testx')
+	stmt:step()
+	stmt:finalize()
+	db:close()
+end
+
+print('shutdown sqlite')
+sqlite.shutdown()
+



CVS commit: src/lib/lua/sqlite

2011-10-15 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sat Oct 15 10:35:06 UTC 2011

Modified Files:
src/lib/lua/sqlite: sqlite.c

Log Message:
Remove un-needed headers.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/lua/sqlite/sqlite.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/lua/sqlite/sqlite.c
diff -u src/lib/lua/sqlite/sqlite.c:1.1 src/lib/lua/sqlite/sqlite.c:1.2
--- src/lib/lua/sqlite/sqlite.c:1.1	Sat Oct 15 10:26:30 2011
+++ src/lib/lua/sqlite/sqlite.c	Sat Oct 15 10:35:06 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: sqlite.c,v 1.1 2011/10/15 10:26:30 mbalmer Exp $ */
+/*	$NetBSD: sqlite.c,v 1.2 2011/10/15 10:35:06 mbalmer Exp $ */
 
 /*
  * Copyright (c) 2011 Marc Balmer m...@msys.ch
@@ -27,15 +27,11 @@
 
 /* SQLite interface for Lua */
 
-#include errno.h
-#include fcntl.h
 #include stdarg.h
 #include stdio.h
 #include string.h
-#include ctype.h
 #include stdlib.h
 #include sqlite3.h
-#include unistd.h
 
 #include lua.h
 #include lauxlib.h



CVS commit: src/lib/lua/sqlite

2011-10-15 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sat Oct 15 12:58:20 UTC 2011

Modified Files:
src/lib/lua/sqlite: sqlite.c

Log Message:
Add db:changes()


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/lua/sqlite/sqlite.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/lua/sqlite/sqlite.c
diff -u src/lib/lua/sqlite/sqlite.c:1.2 src/lib/lua/sqlite/sqlite.c:1.3
--- src/lib/lua/sqlite/sqlite.c:1.2	Sat Oct 15 10:35:06 2011
+++ src/lib/lua/sqlite/sqlite.c	Sat Oct 15 12:58:20 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: sqlite.c,v 1.2 2011/10/15 10:35:06 mbalmer Exp $ */
+/*	$NetBSD: sqlite.c,v 1.3 2011/10/15 12:58:20 mbalmer Exp $ */
 
 /*
  * Copyright (c) 2011 Marc Balmer m...@msys.ch
@@ -182,6 +182,16 @@ db_get_autocommit(lua_State *L)
 }
 
 static int
+db_changes(lua_State *L)
+{
+	sqlite3 **db;
+
+	db = luaL_checkudata(L, 1, SQLITE_DB_METATABLE);
+	lua_pushinteger(L, sqlite3_changes(*db));
+	return 1;
+}
+
+static int
 stmt_bind(lua_State *L)
 {
 	sqlite3_stmt **stmt;
@@ -410,6 +420,7 @@ luaopen_sqlite(lua_State* L)
 		{ errcode,		db_errcode },
 		{ errmsg,		db_errmsg },
 		{ get_autocommit,	db_get_autocommit },
+		{ changes,		db_changes },
 		{ NULL,			NULL }
 	};
 	static const struct luaL_Reg stmt_methods[] = {



CVS commit: src/lib/lua/sqlite

2011-10-15 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sat Oct 15 13:02:24 UTC 2011

Removed Files:
src/lib/lua/sqlite: test-sqlite.lua

Log Message:
Remove, has been moved to share/examples/lua.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r0 src/lib/lua/sqlite/test-sqlite.lua

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/lua/sqlite

2011-10-15 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sun Oct 16 00:45:54 UTC 2011

Modified Files:
src/lib/lua/sqlite: Makefile

Log Message:
Fix dependency.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/lua/sqlite/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/lua/sqlite/Makefile
diff -u src/lib/lua/sqlite/Makefile:1.1 src/lib/lua/sqlite/Makefile:1.2
--- src/lib/lua/sqlite/Makefile:1.1	Sat Oct 15 10:26:30 2011
+++ src/lib/lua/sqlite/Makefile	Sun Oct 16 00:45:54 2011
@@ -1,8 +1,8 @@
-#	$NetBSD: Makefile,v 1.1 2011/10/15 10:26:30 mbalmer Exp $
+#	$NetBSD: Makefile,v 1.2 2011/10/16 00:45:54 mbalmer Exp $
 
 LUA_MODULES=		sqlite
 LUA_SRCS.sqlite=	sqlite.c
 
-LDADD+=			-lsqlite3
-
+LUA_DPLIBS+=		sqlite3 \
+			${.CURDIR}/../../../external/public-domain/sqlite/lib
 .include bsd.lua.mk



CVS commit: src/lib/lua/sqlite

2011-10-15 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sat Oct 15 10:27:06 UTC 2011

Added Files:
src/lib/lua/sqlite: test-sqlite.lua

Log Message:
A small test/demo program to show the sqlite Lua module usage.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/lib/lua/sqlite/test-sqlite.lua

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/lua/sqlite

2011-10-15 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sat Oct 15 10:35:06 UTC 2011

Modified Files:
src/lib/lua/sqlite: sqlite.c

Log Message:
Remove un-needed headers.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/lua/sqlite/sqlite.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/lua/sqlite

2011-10-15 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sat Oct 15 12:58:20 UTC 2011

Modified Files:
src/lib/lua/sqlite: sqlite.c

Log Message:
Add db:changes()


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/lua/sqlite/sqlite.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/lua/sqlite

2011-10-15 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sat Oct 15 13:02:24 UTC 2011

Removed Files:
src/lib/lua/sqlite: test-sqlite.lua

Log Message:
Remove, has been moved to share/examples/lua.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r0 src/lib/lua/sqlite/test-sqlite.lua

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/lua/sqlite

2011-10-15 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sun Oct 16 00:45:54 UTC 2011

Modified Files:
src/lib/lua/sqlite: Makefile

Log Message:
Fix dependency.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/lua/sqlite/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/lua

2011-10-11 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Tue Oct 11 07:10:15 UTC 2011

Modified Files:
src/lib/lua/gpio: Makefile
Added Files:
src/lib/lua: Makefile.inc

Log Message:
use WARNS?=4 for all Lua modules


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/lib/lua/Makefile.inc
cvs rdiff -u -r1.2 -r1.3 src/lib/lua/gpio/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/lua/gpio/Makefile
diff -u src/lib/lua/gpio/Makefile:1.2 src/lib/lua/gpio/Makefile:1.3
--- src/lib/lua/gpio/Makefile:1.2	Mon Oct 10 20:41:05 2011
+++ src/lib/lua/gpio/Makefile	Tue Oct 11 07:10:15 2011
@@ -1,6 +1,5 @@
-#	$NetBSD: Makefile,v 1.2 2011/10/10 20:41:05 christos Exp $
+#	$NetBSD: Makefile,v 1.3 2011/10/11 07:10:15 plunky Exp $
 
-WARNS?=	4
 LUA_MODULES=	gpio
 LUA_SRCS.gpio=	gpio.c
 

Added files:

Index: src/lib/lua/Makefile.inc
diff -u /dev/null src/lib/lua/Makefile.inc:1.1
--- /dev/null	Tue Oct 11 07:10:15 2011
+++ src/lib/lua/Makefile.inc	Tue Oct 11 07:10:15 2011
@@ -0,0 +1,3 @@
+#	$NetBSD: Makefile.inc,v 1.1 2011/10/11 07:10:15 plunky Exp $
+
+WARNS?=	4



CVS commit: src/lib/lua

2011-10-11 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Tue Oct 11 07:10:15 UTC 2011

Modified Files:
src/lib/lua/gpio: Makefile
Added Files:
src/lib/lua: Makefile.inc

Log Message:
use WARNS?=4 for all Lua modules


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/lib/lua/Makefile.inc
cvs rdiff -u -r1.2 -r1.3 src/lib/lua/gpio/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/lua/gpio

2011-10-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Oct 10 20:41:05 UTC 2011

Modified Files:
src/lib/lua/gpio: Makefile gpio.c

Log Message:
turn on warnings, and fix compilation issues.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/lua/gpio/Makefile
cvs rdiff -u -r1.2 -r1.3 src/lib/lua/gpio/gpio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/lua/gpio/Makefile
diff -u src/lib/lua/gpio/Makefile:1.1 src/lib/lua/gpio/Makefile:1.2
--- src/lib/lua/gpio/Makefile:1.1	Sat Oct  8 04:36:27 2011
+++ src/lib/lua/gpio/Makefile	Mon Oct 10 16:41:05 2011
@@ -1,5 +1,6 @@
-#	$NetBSD: Makefile,v 1.1 2011/10/08 08:36:27 mbalmer Exp $
+#	$NetBSD: Makefile,v 1.2 2011/10/10 20:41:05 christos Exp $
 
+WARNS?=	4
 LUA_MODULES=	gpio
 LUA_SRCS.gpio=	gpio.c
 

Index: src/lib/lua/gpio/gpio.c
diff -u src/lib/lua/gpio/gpio.c:1.2 src/lib/lua/gpio/gpio.c:1.3
--- src/lib/lua/gpio/gpio.c:1.2	Sat Oct  8 04:46:40 2011
+++ src/lib/lua/gpio/gpio.c	Mon Oct 10 16:41:05 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: gpio.c,v 1.2 2011/10/08 08:46:40 mbalmer Exp $ */
+/*	$NetBSD: gpio.c,v 1.3 2011/10/10 20:41:05 christos Exp $ */
 
 /*
  * Copyright (c) 2011 Marc Balmer m...@msys.ch
@@ -112,7 +112,7 @@ gpio_get_pin(lua_State *L, int n, struct
 {
 	switch (lua_type(L, n)) {
 	case LUA_TNUMBER:
-		req-gp_pin = lua_tointeger(L, n) - 1;	/* 1 based! */
+		req-gp_pin = (int)lua_tointeger(L, n) - 1;	/* 1 based! */
 		break;
 	case LUA_TSTRING:
 		strlcpy(req-gp_name, lua_tostring(L, n), sizeof(req-gp_name));
@@ -131,8 +131,8 @@ gpio_set(lua_State *L)
 
 	fd = luaL_checkudata(L, 1, GPIO_METATABLE);
 	memset(set, 0, sizeof(set));
-	gpio_get_pin(L, 2, (struct gpio_req *)set);
-	set.gp_flags = luaL_checkinteger(L, 3);
+	gpio_get_pin(L, 2, (void *)set);
+	set.gp_flags = (int)luaL_checkinteger(L, 3);
 	if (ioctl(*fd, GPIOSET, set) == -1)
 		gpio_error(L, GPIOSET);
 	return 0;
@@ -146,7 +146,7 @@ gpio_unset(lua_State *L)
 
 	fd = luaL_checkudata(L, 1, GPIO_METATABLE);
 	memset(set, 0, sizeof(set));
-	gpio_get_pin(L, 2, (struct gpio_req *)set);
+	gpio_get_pin(L, 2, (void *)set);
 	if (ioctl(*fd, GPIOUNSET, set) == -1)
 		gpio_error(L, GPIOUNSET);
 	return 0;
@@ -175,7 +175,7 @@ gpio_write(lua_State *L)
 	int *fd, val;
 
 	fd = luaL_checkudata(L, 1, GPIO_METATABLE);
-	val = luaL_checkinteger(L, 3);
+	val = (int)luaL_checkinteger(L, 3);
 	if (val != GPIO_PIN_HIGH  val != GPIO_PIN_LOW)
 		gpio_error(L, %d: invalid value, val);
 	memset(req, 0, sizeof(req));
@@ -191,7 +191,7 @@ static int
 gpio_toggle(lua_State *L)
 {
 	struct gpio_req req;
-	int *fd, val;
+	int *fd;
 
 	fd = luaL_checkudata(L, 1, GPIO_METATABLE);
 	memset(req, 0, sizeof(req));
@@ -212,10 +212,10 @@ gpio_attach(lua_State *L)
 	memset(attach, 0, sizeof(attach));
 	strlcpy(attach.ga_dvname, luaL_checkstring(L, 2),
 	sizeof(attach.ga_dvname));
-	attach.ga_offset = luaL_checkinteger(L, 3);
-	attach.ga_mask = luaL_checkinteger(L, 4);
+	attach.ga_offset = (int)luaL_checkinteger(L, 3);
+	attach.ga_mask = (int)luaL_checkinteger(L, 4);
 	if (lua_gettop(L)  4)
-		attach.ga_flags = luaL_checkinteger(L, 5);
+		attach.ga_flags = (int)luaL_checkinteger(L, 5);
 	else
 		attach.ga_flags = 0;
 
@@ -228,7 +228,7 @@ static int
 gpio_pulse(lua_State *L)
 {
 	struct gpio_pulse pulse;
-	suseconds_t period, on, off;
+	suseconds_t period, on, off, sec;
 	double freq, dc;
 	int *fd;
 
@@ -241,7 +241,7 @@ gpio_pulse(lua_State *L)
 		freq, dc);
 
 	memset(pulse, 0, sizeof(pulse));
-	gpio_get_pin(L, 2, (struct gpio_req *)pulse);
+	gpio_get_pin(L, 2, (void *)pulse);
 
 	if (freq  0.0  dc  0.0) {
 		period = 100 / freq;
@@ -249,16 +249,16 @@ gpio_pulse(lua_State *L)
 		off = period - on;
 
 		if (on = 100) {
-			pulse.gp_pulse_on.tv_sec = on / 100;
-			on -= pulse.gp_pulse_on.tv_sec * 100;
+			pulse.gp_pulse_on.tv_sec = sec = on / 100;
+			on -= sec * 100;
 			pulse.gp_pulse_on.tv_usec = on;
 		} else {
 			pulse.gp_pulse_on.tv_sec = 0;
 			pulse.gp_pulse_on.tv_usec = on;
 		}
 		if (off = 100) {
-			pulse.gp_pulse_off.tv_sec = off / 100;
-			off -= pulse.gp_pulse_off.tv_sec * 100;
+			pulse.gp_pulse_off.tv_sec = sec = off / 100;
+			off -= sec * 100;
 			pulse.gp_pulse_off.tv_usec = off;
 		} else {
 			pulse.gp_pulse_off.tv_sec = 0;
@@ -271,14 +271,15 @@ gpio_pulse(lua_State *L)
 
 	if (ioctl(*fd, GPIOPULSE, pulse) == -1)
 		gpio_error(L, GPIOPULSE);
+	return 0;
 }
 
 struct constant {
-	char *name;
+	const char *name;
 	int value;
 };
 
-static struct constant gpio_constant[] = {
+static const struct constant gpio_constant[] = {
 	/* GPIO pin states */
 	{ PIN_LOW,		GPIO_PIN_LOW },
 	{ PIN_HIGH,		GPIO_PIN_HIGH },
@@ -317,6 +318,8 @@ gpio_set_info(lua_State *L)
 	lua_settable(L, -3);
 }
 
+int luaopen_gpio(lua_State*);
+
 int
 luaopen_gpio(lua_State* L)
 {



CVS commit: src/lib/lua

2011-10-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Oct 10 20:43:00 UTC 2011

Modified Files:
src/lib/lua: Makefile

Log Message:
Handle sun2


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/lua/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/lua/Makefile
diff -u src/lib/lua/Makefile:1.2 src/lib/lua/Makefile:1.3
--- src/lib/lua/Makefile:1.2	Sat Oct  8 09:14:04 2011
+++ src/lib/lua/Makefile	Mon Oct 10 16:43:00 2011
@@ -1,5 +1,10 @@
-#	$NetBSD: Makefile,v 1.2 2011/10/08 13:14:04 mbalmer Exp $
+#	$NetBSD: Makefile,v 1.3 2011/10/10 20:43:00 christos Exp $
 
+.include bsd.own.mk
+
+.if ${MACHINE_ARCH} != m68000
+# No support for shared libraries and pic code.
 SUBDIR+=	gpio
+.endif
 
 .include bsd.subdir.mk



CVS commit: src/lib/lua/gpio

2011-10-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Oct 10 20:41:05 UTC 2011

Modified Files:
src/lib/lua/gpio: Makefile gpio.c

Log Message:
turn on warnings, and fix compilation issues.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/lua/gpio/Makefile
cvs rdiff -u -r1.2 -r1.3 src/lib/lua/gpio/gpio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/lua/gpio

2011-10-08 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sat Oct  8 08:36:27 UTC 2011

Added Files:
src/lib/lua/gpio: Makefile

Log Message:
Makefile to build gpio.so.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/lib/lua/gpio/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/lib/lua/gpio/Makefile
diff -u /dev/null src/lib/lua/gpio/Makefile:1.1
--- /dev/null	Sat Oct  8 08:36:27 2011
+++ src/lib/lua/gpio/Makefile	Sat Oct  8 08:36:27 2011
@@ -0,0 +1,6 @@
+#	$NetBSD: Makefile,v 1.1 2011/10/08 08:36:27 mbalmer Exp $
+
+LUA_MODULES=	gpio
+LUA_SRCS.gpio=	gpio.c
+
+.include bsd.lua.mk



CVS commit: src/lib/lua/gpio

2011-10-08 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sat Oct  8 08:46:40 UTC 2011

Modified Files:
src/lib/lua/gpio: gpio.c

Log Message:
Add NetBSD CVS marker, remove some whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/lua/gpio/gpio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/lua/gpio/gpio.c
diff -u src/lib/lua/gpio/gpio.c:1.1 src/lib/lua/gpio/gpio.c:1.2
--- src/lib/lua/gpio/gpio.c:1.1	Fri Oct  7 21:14:19 2011
+++ src/lib/lua/gpio/gpio.c	Sat Oct  8 08:46:40 2011
@@ -1,3 +1,5 @@
+/*	$NetBSD: gpio.c,v 1.2 2011/10/08 08:46:40 mbalmer Exp $ */
+
 /*
  * Copyright (c) 2011 Marc Balmer m...@msys.ch
  * All rights reserved.
@@ -185,7 +187,6 @@ gpio_write(lua_State *L)
 	return 1;
 }
 
-
 static int
 gpio_toggle(lua_State *L)
 {
@@ -201,7 +202,6 @@ gpio_toggle(lua_State *L)
 	return 1;
 }
 
-
 static int
 gpio_attach(lua_State *L)
 {
@@ -224,7 +224,6 @@ gpio_attach(lua_State *L)
 	return 0;
 }
 
-
 static int
 gpio_pulse(lua_State *L)
 {



CVS commit: src/lib/lua/gpio

2011-10-08 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sat Oct  8 08:36:27 UTC 2011

Added Files:
src/lib/lua/gpio: Makefile

Log Message:
Makefile to build gpio.so.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/lib/lua/gpio/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/lua/gpio

2011-10-08 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sat Oct  8 08:46:40 UTC 2011

Modified Files:
src/lib/lua/gpio: gpio.c

Log Message:
Add NetBSD CVS marker, remove some whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/lua/gpio/gpio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/lua

2011-10-07 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Fri Oct  7 21:23:32 UTC 2011

Added Files:
src/lib/lua: Makefile

Log Message:
Add stub Makefile, not yet called.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/lib/lua/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/lib/lua/Makefile
diff -u /dev/null src/lib/lua/Makefile:1.1
--- /dev/null	Fri Oct  7 21:23:32 2011
+++ src/lib/lua/Makefile	Fri Oct  7 21:23:32 2011
@@ -0,0 +1,3 @@
+#	$NetBSD: Makefile,v 1.1 2011/10/07 21:23:32 mbalmer Exp $
+
+.include bsd.subdir.mk



CVS commit: src/lib/lua/gpio

2011-10-07 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Fri Oct  7 21:14:19 UTC 2011

Added Files:
src/lib/lua/gpio: gpio.c

Log Message:
Interface gpio(4) from Lua.  Not linked to the build.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/lib/lua/gpio/gpio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/lua

2011-10-07 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Fri Oct  7 21:23:32 UTC 2011

Added Files:
src/lib/lua: Makefile

Log Message:
Add stub Makefile, not yet called.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/lib/lua/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.