xiaoxiang781216 commented on a change in pull request #1075: URL: https://github.com/apache/incubator-nuttx-apps/pull/1075#discussion_r830577173
########## File path: interpreters/lua/Makefile ########## @@ -0,0 +1,133 @@ +############################################################################ +# apps/interpreters/lua/Makefile +# +# 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 $(APPDIR)/Make.defs + +# Lua built-in application info + +PROGNAME = lua +PRIORITY = $(CONFIG_INTERPRETER_LUA_PRIORITY) +STACKSIZE = $(CONFIG_INTERPRETER_LUA_STACKSIZE) +MODULE = $(CONFIG_INTERPRETERS_LUA) + +# Lua library + +LUA_VERSION = $(patsubst "%",%,$(strip $(CONFIG_INTERPRETER_LUA_VERSION))) +LUA_TARBALL = lua-$(LUA_VERSION).tar.gz +LUA_UNPACK = lua-$(LUA_VERSION) +LUA_URL_BASE = http://www.lua.org/ftp +LUA_URL = $(LUA_URL_BASE)$(DELIM)$(LUA_TARBALL) Review comment: $(DELIM)->/? $(DELIM) is only used for the local path ########## File path: interpreters/lua/Module.mk ########## @@ -0,0 +1,37 @@ +############################################################################ +# apps/interpreters/lua/Module.mk +# +# 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. +# +############################################################################ + +LUAMOD_REGISTRY = $(APPDIR)$(DELIM)interpreters$(DELIM)lua$(DELIM)registry + +define LUAMOD_REGISTER + $(Q) echo Register Lua Module: $1 + $(Q) echo { \"$1\", $2 }, > "$(LUAMOD_REGISTRY)$(DELIM)$1.bdat" + $(Q) echo "int $2(lua_State *L);" > "$(LUAMOD_REGISTRY)$(DELIM)$1.pdat" + $(Q) touch "$(LUAMOD_REGISTRY)$(DELIM).updated" +endef + +ifneq ($(LUAMODNAME),) + Review comment: remove the blank line? ########## File path: interpreters/lua/nuttx_linit.c ########## @@ -0,0 +1,67 @@ +/**************************************************************************** + * apps/interpreters/lua/nuttx_linit.c + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stddef.h> + +#include <lua.h> +#include <lualib.h> +#include <lauxlib.h> + +#include <nuttx/config.h> + +#include "luamod_proto.h" + +/**************************************************************************** + * Private Data + *****************************************************************************/ + +static const luaL_Reg loadedlibs[] = { +#ifdef CONFIG_INTERPRETER_LUA_CORE_LIBS + {"_G", luaopen_base}, Review comment: Thanks for explanation. For "_G", look like LUA_GNAME is defined in lauxlib.h? Can we use this macro directly? ########## File path: examples/lua_module/luamod_hello.c ########## @@ -0,0 +1,76 @@ +/**************************************************************************** + * apps/examples/lua_module/luamod_hello.c + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <lua.h> +#include <lauxlib.h> + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int say_hello(lua_State *L); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct luaL_Reg hello[] = Review comment: add g_ prefix to follow the coding style ########## File path: interpreters/lua/nuttx_linit.c ########## @@ -0,0 +1,68 @@ +/**************************************************************************** + * apps/interpreters/lua/nuttx_linit.c + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stddef.h> + +#include <lua.h> +#include <lualib.h> +#include <lauxlib.h> + +#include <nuttx/config.h> + +#include "luamod_proto.h" + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const luaL_Reg loadedlibs[] = Review comment: add g_ prefix too. ########## File path: interpreters/lua/Makefile ########## @@ -0,0 +1,133 @@ +############################################################################ +# apps/interpreters/lua/Makefile +# +# 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 $(APPDIR)/Make.defs + +# Lua built-in application info + +PROGNAME = lua +PRIORITY = $(CONFIG_INTERPRETER_LUA_PRIORITY) +STACKSIZE = $(CONFIG_INTERPRETER_LUA_STACKSIZE) +MODULE = $(CONFIG_INTERPRETERS_LUA) + +# Lua library + +LUA_VERSION = $(patsubst "%",%,$(strip $(CONFIG_INTERPRETER_LUA_VERSION))) +LUA_TARBALL = lua-$(LUA_VERSION).tar.gz +LUA_UNPACK = lua-$(LUA_VERSION) +LUA_URL_BASE = http://www.lua.org/ftp +LUA_URL = $(LUA_URL_BASE)$(DELIM)$(LUA_TARBALL) +LUA_SRC = $(LUA_UNPACK)$(DELIM)src + +MAINSRC = $(LUA_SRC)$(DELIM)lua.c +CORELIB_SRCS = $(filter-out $(LUA_SRC)$(DELIM)lauxlib.c,$(wildcard $(LUA_SRC)$(DELIM)*lib.c)) +EXCLUDE_SRCS = $(MAINSRC) $(CORELIB_SRCS) $(LUA_SRC)$(DELIM)luac.c $(LUA_SRC)$(DELIM)linit.c +CSRCS = $(filter-out $(EXCLUDE_SRCS),$(wildcard $(LUA_SRC)$(DELIM)*.c)) +CSRCS += nuttx_linit.c + +CFLAGS += -DLUA_MAXINPUT=$(CONFIG_INTERPRETER_LUA_IOBUFSIZE) +CFLAGS += -DLUA_PROGNAME=\"$(PROGNAME)\" + +ifeq ($(CONFIG_INTERPRETER_LUA_32BITS),y) +CFLAGS += -DLUA_32BITS +endif + +ifneq ($(CONFIG_INTERPRETER_LUA_PATH),"") +CFLAGS += -DLUA_PATH_DEFAULT=\"$(CONFIG_INTERPRETER_LUA_PATH)\" +endif + +ifneq ($(CONFIG_INTERPRETER_LUA_CPATH),"") +CFLAGS += -DLUA_CPATH_DEFAULT=\"$(CONFIG_INTERPRETER_LUA_CPATH)\" +endif + +ifeq ($(CONFIG_SYSTEM_READLINE),y) +CFLAGS += -include "system/readline.h" +CFLAGS += -D'lua_initreadline(L)=((void)L)' +CFLAGS += -D'lua_readline(L,b,p)=((void)L,fputs(p,stdout),fflush(stdout),readline(b,LUA_MAXINPUT,stdin,stdout))' +CFLAGS += -D'lua_saveline(L,line)={(void)L;(void)line;}' +CFLAGS += -D'lua_freeline(L,line)={(void)L;(void)b;}' +endif + +# Lua download and unpack + +$(LUA_TARBALL): + $(Q) echo "Downloading $(LUA_TARBALL)" + $(Q) curl -O -L $(LUA_URL) + +$(LUA_UNPACK): $(LUA_TARBALL) + $(Q) echo "Unpacking $(LUA_TARBALL) to $(LUA_UNPACK)" + $(Q) tar -xvzf $(LUA_TARBALL) + +context:: $(LUA_UNPACK) + +# Register core modules + +ifeq ($(CONFIG_INTERPRETER_LUA_CORE_LIBS),y) Review comment: CONFIG_INTERPRETER_LUA_CORE_LIBS->CONFIG_INTERPRETER_LUA_CORELIB to math CORELIB_SRCS? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
