You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2012/06/12 17:51:37 UTC
[25/50] git commit: Separate Lua API bindings from the remap module
Separate Lua API bindings from the remap module
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/4df83daa
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/4df83daa
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/4df83daa
Branch: refs/heads/jpeach/lua
Commit: 4df83daa97bd7b212de883a09121991c7499f5f1
Parents: 1d08a67
Author: James Peach <jp...@apache.org>
Authored: Wed Apr 11 21:24:14 2012 -0700
Committer: James Peach <jp...@apache.org>
Committed: Tue Jun 12 08:48:35 2012 -0700
----------------------------------------------------------------------
plugins/lua/Makefile.am | 2 +-
plugins/lua/lapi.cc | 65 ++++++++++++++++++++++++++++++++++++++++++
plugins/lua/lua.cc | 40 ++++++-------------------
3 files changed, 76 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4df83daa/plugins/lua/Makefile.am
----------------------------------------------------------------------
diff --git a/plugins/lua/Makefile.am b/plugins/lua/Makefile.am
index 6878e8c..6cc863a 100644
--- a/plugins/lua/Makefile.am
+++ b/plugins/lua/Makefile.am
@@ -27,7 +27,7 @@ AM_CXXFLAGS = \
pkglib_LTLIBRARIES = lua.la
lua_la_LIBADD = ${LUA_LIB}
-lua_la_SOURCES = lua.cc
+lua_la_SOURCES = lua.cc lapi.cc
lua_la_LDFLAGS = -module -avoid-version -shared
endif
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4df83daa/plugins/lua/lapi.cc
----------------------------------------------------------------------
diff --git a/plugins/lua/lapi.cc b/plugins/lua/lapi.cc
new file mode 100644
index 0000000..8ecdf14
--- /dev/null
+++ b/plugins/lua/lapi.cc
@@ -0,0 +1,65 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#include <ts/ts.h>
+#include <ts/remap.h>
+
+extern "C" {
+#include <lua.h>
+#include <lualib.h>
+#include <lauxlib.h>
+}
+
+#include <unistd.h>
+
+static int
+TSLuaDebug(lua_State * lua)
+{
+ const char * tag = luaL_checkstring(lua, 1);
+ const char * message = luaL_checkstring(lua, 2);
+
+ TSDebug(tag, "%s", message);
+ return 0;
+}
+
+static const luaL_Reg LUAEXPORTS[] =
+{
+ { "debug", TSLuaDebug },
+ { NULL, NULL}
+};
+
+int
+LuaApiInit(lua_State * lua)
+{
+ TSDebug("lua", "initializing Lua API");
+
+ lua_newtable(lua);
+
+ // Register functions in the "ts" module.
+ luaL_register(lua, NULL, LUAEXPORTS);
+
+ // Push constants into the "ts" module.
+ lua_pushinteger(lua, TSREMAP_DID_REMAP_STOP);
+ lua_setfield(lua, -2, "REMAP_COMPLETE");
+
+ lua_pushinteger(lua, TSREMAP_DID_REMAP);
+ lua_setfield(lua, -2, "REMAP_CONTINUE");
+
+ TSReleaseAssert(lua_istable(lua, -1) == 1);
+ return 1;
+}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4df83daa/plugins/lua/lua.cc
----------------------------------------------------------------------
diff --git a/plugins/lua/lua.cc b/plugins/lua/lua.cc
index b08bb53..37ed384 100644
--- a/plugins/lua/lua.cc
+++ b/plugins/lua/lua.cc
@@ -27,6 +27,8 @@ extern "C" {
#include <unistd.h>
+extern int LuaApiInit(lua_State *);
+
static void *
LuaAllocate(void * ud, void * ptr, size_t osize, size_t nsize)
{
@@ -40,22 +42,6 @@ LuaAllocate(void * ud, void * ptr, size_t osize, size_t nsize)
return TSrealloc(ptr, nsize);
}
-static int
-TSLuaDebug(lua_State * lua)
-{
- const char * tag = luaL_checkstring(lua, 1);
- const char * message = luaL_checkstring(lua, 2);
-
- TSDebug(tag, "%s", message);
- return 0;
-}
-
-static const luaL_Reg LUAEXPORTS[] =
-{
- { "debug", TSLuaDebug },
- { NULL, NULL}
-};
-
static TSReturnCode
LuaPluginInit(lua_State * lua)
{
@@ -157,22 +143,16 @@ TSRemapNewInstance(int argc, char * argv[], void ** ih, char * errbuf, int errbu
luaL_openlibs(lua);
- // Register functions in the "ts" module.
- luaL_register(lua, "ts", LUAEXPORTS);
-
- // Get the "ts" module table back on the stack.
- lua_getglobal(lua, "ts");
- TSReleaseAssert(lua_istable(lua, -1));
+ // Pull up the preload table.
+ lua_getglobal(lua, "package");
+ lua_getfield(lua, -1, "preload");
+ lua_remove(lua, -2);
- // Push constants into the "ts" module.
- lua_pushinteger(lua, TSREMAP_DID_REMAP_STOP);
- lua_setfield(lua, -2, "REMAP_COMPLETE");
+ // Register LuaApiInit to load the 'ts' package.
+ lua_pushcfunction(lua, LuaApiInit);
+ lua_setfield(lua, -2, "ts");
- lua_pushinteger(lua, TSREMAP_DID_REMAP);
- lua_setfield(lua, -2, "REMAP_CONTINUE");
-
- // Pop the "ts" module table.
- lua_pop(lua, 1);
+ lua_pop(lua, -1);
for (int i = 0; i < argc; ++i) {
if (access(argv[i], R_OK) == 0) {