Library of manipulating Python in Lua.
This project is under development...
Create an issue if any bug occurred.
This project is only supported on Linux temporarily.
-
Install Lua and Python. (latest version recommended)
-
Build & install this project.
git clone https://github.com/imitoy/luapython.git
cd luapython
sudo luarocks install luapython-0.1.1-1.rockspec # require python headers
# when uninstall, replace 'install' with 'remove'- Import this library in Lua.
-- Import all
luapython=require "luapython"
-- Then use luapython.import, luapython.dict ...
-- Import all to _G or other env
luapython=require "luapython"
luapython:init(_G)
-- Then use _G.import, _G.dict ...
-- Import specific function
import=require "luapython.import"
-- Then use import- Import python modules in Lua.
numpy=import"numpy" -- Make sure numpy is installed
print(numpy.array({1,2,3}))
math=import"math"
print(math.tan(90))- Create Python structure by using
dict,set,list,tuple.
json=import"json"
local data = dict{name="Alice", age=18}
print(json.dumps(data))- Create a table to adapt keywords parameters.
OpenAI = import"openai.OpenAI"
local client = OpenAI({api_key="<DeepSeek API Key>", base_url="https://api.deepseek.com"})
local response = client.chat.completions.create({
model="deepseek-chat",
messages={
{role = "system", content = "You are a helpful assistant"},
{role = "user", content = "Hello"},
},
stream=false
})
print(response.choices[0].message.content)- Append
()to the Python Iter Object.
local response = client.chat.completions.create({
model="deepseek-chat",
messages={
{role = "system", content = "You are a helpful assistant"},
{role = "user", content = "Hello"},
},
stream=true
})
for chunk in response() do
io.write(chunk.choices[0].delta.content)
io.flush()
end- Support for Python version 3.x
- Conda support
- Integrate Python error in Lua