35 lines
873 B
Lua
35 lines
873 B
Lua
|
-- Example Lua script to demonstrate Go-Lua integration
|
||
|
|
||
|
-- Access the config table passed from Go
|
||
|
print("Script started")
|
||
|
print("App name:", config.appName)
|
||
|
print("Version:", config.version)
|
||
|
print("Features:", table.concat(config.features, ", "))
|
||
|
|
||
|
-- Call the Go function
|
||
|
local response = printFromGo("Hello from Lua!")
|
||
|
print("Response from Go:", response)
|
||
|
|
||
|
-- Function that will be called from Go
|
||
|
function getResult()
|
||
|
local result = {
|
||
|
status = "success",
|
||
|
calculations = {
|
||
|
sum = 10 + 20,
|
||
|
product = 5 * 7
|
||
|
},
|
||
|
message = "Calculation completed"
|
||
|
}
|
||
|
return result
|
||
|
end
|
||
|
|
||
|
-- Load external module (if available)
|
||
|
local success, utils = pcall(require, "utils")
|
||
|
if success then
|
||
|
print("Utils module loaded")
|
||
|
utils.doSomething()
|
||
|
else
|
||
|
print("Utils module not available:", utils)
|
||
|
end
|
||
|
|
||
|
print("Script completed")
|