SlideShare a Scribd company logo
1 of 33
Download to read offline
Go, meet Lua
Using Lua in Go and vice-versa!
André Burgaud @andreburgaud
4/15/2020
You 💖Go... Why would you need Lua?
● NGINX (OpenResty)
● Wireshark
● Nmap
● Pandoc
● HAProxy
● Redis
● Roblox
● Rockbox
● SciTE
● LÖVE
Agenda
● CGO
○ Using C from Go (inline code and separate files)
○ Using Go from C (export)
● Embedding Lua in Go (CGO)
○ Executing a lua script from Go
○ Building a basic Lua REPL in Go
● Extending Lua with Go
○ LuaJIT FFI
● Using a Lua Interpreter in Go
CGO ☠
CGO - Inline C code in GO
Go code
C code in Go comments
main.go
I’m using C
code!
CGO - Inline C code in GO (code/demo)
package main
/*
#include <stdio.h>
void hello() {
printf("Hello from C!n");
}
*/
import "C" // No new line between block comment and 'import "C"'
func main() {
C.hello()
}
CGO - Separate *.h and *.c Files
Go code
C code in Go comments
Go code
header files in Go comments
main.go
hello.h
hello.a
exe
hello.c
①
②
CGO - Separate *.h and *.c Files (code/demo)
package main
// #include <stdlib.h>
// #include <hello.h>
import "C"
import (
"unsafe"
)
func main() {
C.hello()
name := C.CString("GoMN")
defer C.free(unsafe.Pointer(name))
C.print(name)
}
main.c
CGO - Using Go from C (export)
Include golib.h
Go code with
Exported functions
main.go
golib.h
golib.so
a.out
①
②
-buildmode=c-shared
golib.so
③
a.out
No fair! C is
using me!
CGO - Using Go from C (code / demo)
package main
import (
"C"
"os"
)
//export Pwd
func Pwd() *C.char {
d, err := os.Getwd()
if err != nil {
return C.CString("Error")
}
return C.CString(d)
}
func main() {}
Embedding Lua in Go
Executing a Lua Script in Go
Go code
C code in Go comments
Go code
Executes hello.lua
header files and
CGO linking
in Go comments
main.go
lua*.h
liblua.a
exe
lauxlib.h
I’m using
Lua C code!
hello.lua
Executing a Lua Script in Go
● CGO ☠ … Again
● Problem with C Macros - #define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL)
● Unsafe pointers (need to free allocated memory)
Building a Lua REPL in Go
Go code
C code in Go comments
Go code
Executes REPL loop and
Interpretes Lua instructions
header files and
CGO linking
in Go comments
main.go
lua*.h
liblua.a
exe
lauxlib.h
I’m using
Lua C code!
>>> print “hello”
Building a Lua REPL in Go
● Here we CGO ☠ … Again
● Problem with C Macros - #define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL)
● Unsafe
● Hard to debug
Extending Lua with Go
Extend LuaJIT with Go
Go code with
Exported functions
main.go
golib.so
①
②
-buildmode=c-shared
$ luajit getcwd.lua
/a/b/c/d
$
getcwd.lua
I’m happy to
give a hand
to my friend
Lua
Extend LuaJIT with Go
● LuaJIT FFI
● Extend Lua to include functions not available in the interpreter STL
● Example: current working directory
● In Go: os.Getwd()
○ Export function in Go
○ Use the FFI module available in LuaJIT (calling external C functions)
○ Add C declaration
○ Call the Go function (LuaJIT sees it as a C function)
Export Function in Go (same as C example)
package main
import "C"
import (
"os"
)
//export Pwd
func Pwd() *C.char {
d, err := os.Getwd()
if err != nil {
return C.CString("Error")
}
return C.CString(d)
}
func main() {}
Using a Lua Interpreter in Go
Lua Interpreter in Go 💖
● https://github.com/yuin/gopher-lua
● DoString()
● DoFile()
● Base64 (Bi-directional)
Lua Interpreter in Go 💖
Go code
C code in Go comments
💘
Import gopher-lua
Go code
Executes and extends lua
code
main.go
Go plugin
● Allows creating modular Go programs
● Allows reusing “plugins” across multiple programs
● https://golang.org/pkg/plugin/
$ go build -buildmode=plugin
Ideas 💡
● Configuration files
● Expose internal APIs
● Extension/Customization (games)
● Templating language (HTML, XML, next ML or JSON…)
● Filtering text processing (pandoc)
● ...
Summary
● Quick review of CGO
● Embed Lua in Go (CGO)
● Extend LuaJIT with Go (FFI)
● Embed and Extend with a Lua interpreter written in Go
● More ideas to explore
Go Online Resources
● https://github.com/andreburgaud/meetup-golang-lua Source code
● https://golang.org/cmd/cgo/ Command cgo
● https://nick.groenen.me/posts/plugins-in-go-18/ Plugins in Go 1.8
● https://medium.com/learning-the-go-programming-language/writing-modular-g
o-programs-with-plugins-ec46381ee1a9 Writing Modular Go Programs with
Plugins
● https://docs.google.com/document/d/1nr-TQHw_er6GOQRsF6T43GGhFDelr
AP0NqSS_00RgZ Go Execution Modes
Lua Interpreters in Go
● https://github.com/Azure/golua A Lua 5.3 engine implemented in Go (MIT)
● https://github.com/Shopify/go-lua A Lua VM in Go (MIT)
● https://github.com/yuin/gopher-lua GopherLua: VM and compiler for Lua in Go
(MIT)
● https://github.com/milochristiansen/lua A Lua 5.3 VM and compiler written in
Go (Zlib)
Go Books
● https://nostarch.com/blackhatgo Black Hat Go
● https://www.gopl.io/ The Go Programming Language
● https://www.packtpub.com/programming/mastering-go-second-edition
Mastering Go
Lua Online Resources
● https://www.lua.org/ Lua Web Site
● https://luajit.org/ The LuaJIT Project
● https://www.oreilly.com/content/learn-lua-from-javascript-part-1-an-introductio
n-to-lua/ Learn Lua from JavaScript, part 1: An introduction to Lua
Lua Books
● https://www.lua.org/pil/ Programming in Lua
● https://www.packtpub.com/application-development/lua-quick-start-guide Lua
Quick Start Guide
Other Resources
● https://love2d.org/ LÖVE
● https://github.com/love2d/love LÖVE
Attributions
● Lua Logo: By Alexandre Nakonechnyj (Grafik-Design) und Lua-Team
(PostScript-Code) - svg from PostScript Source (see below) created from
Lumu, Public Domain,
https://commons.wikimedia.org/w/index.php?curid=37714918
● Gopher: By Takuya Ueda (https://twitter.com/tenntenn). Licensed under the
Creative Commons 3.0 Attributions license,
https://github.com/golang-samples/gopher-vector
License
● Copyright © 2020 by Andre Burgaud https://burgaud.com
● Released under https://creativecommons.org/licenses/by/4.0/

More Related Content

What's hot

組み込みでこそC++を使う10の理由
組み込みでこそC++を使う10の理由組み込みでこそC++を使う10の理由
組み込みでこそC++を使う10の理由
kikairoya
 
[JCConf 2023] 從 Kotlin Multiplatform 到 Compose Multiplatform:在多平台間輕鬆共用業務邏輯與 U...
[JCConf 2023] 從 Kotlin Multiplatform 到 Compose Multiplatform:在多平台間輕鬆共用業務邏輯與 U...[JCConf 2023] 從 Kotlin Multiplatform 到 Compose Multiplatform:在多平台間輕鬆共用業務邏輯與 U...
[JCConf 2023] 從 Kotlin Multiplatform 到 Compose Multiplatform:在多平台間輕鬆共用業務邏輯與 U...
Shengyou Fan
 

What's hot (20)

The Internals of "Hello World" Program
The Internals of "Hello World" ProgramThe Internals of "Hello World" Program
The Internals of "Hello World" Program
 
Introduction to gdb
Introduction to gdbIntroduction to gdb
Introduction to gdb
 
from Source to Binary: How GNU Toolchain Works
from Source to Binary: How GNU Toolchain Worksfrom Source to Binary: How GNU Toolchain Works
from Source to Binary: How GNU Toolchain Works
 
BoostAsioで可読性を求めるのは間違っているだろうか
BoostAsioで可読性を求めるのは間違っているだろうかBoostAsioで可読性を求めるのは間違っているだろうか
BoostAsioで可読性を求めるのは間違っているだろうか
 
Reconnaissance of Virtio: What’s new and how it’s all connected?
Reconnaissance of Virtio: What’s new and how it’s all connected?Reconnaissance of Virtio: What’s new and how it’s all connected?
Reconnaissance of Virtio: What’s new and how it’s all connected?
 
Effective CMake
Effective CMakeEffective CMake
Effective CMake
 
Interpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratchInterpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratch
 
組み込みでこそC++を使う10の理由
組み込みでこそC++を使う10の理由組み込みでこそC++を使う10の理由
組み込みでこそC++を使う10の理由
 
[DockerCon 2020] Hardening Docker daemon with Rootless Mode
[DockerCon 2020] Hardening Docker daemon with Rootless Mode[DockerCon 2020] Hardening Docker daemon with Rootless Mode
[DockerCon 2020] Hardening Docker daemon with Rootless Mode
 
SR-IOV Networking in OpenStack - OpenStack最新情報セミナー 2016年3月
SR-IOV Networking in OpenStack - OpenStack最新情報セミナー 2016年3月SR-IOV Networking in OpenStack - OpenStack最新情報セミナー 2016年3月
SR-IOV Networking in OpenStack - OpenStack最新情報セミナー 2016年3月
 
GDB Rocks!
GDB Rocks!GDB Rocks!
GDB Rocks!
 
Vue Storefront Basics
Vue Storefront BasicsVue Storefront Basics
Vue Storefront Basics
 
Golang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageGolang - Overview of Go (golang) Language
Golang - Overview of Go (golang) Language
 
Cross-platform UI Engines Rendering Performance
Cross-platform UI Engines Rendering PerformanceCross-platform UI Engines Rendering Performance
Cross-platform UI Engines Rendering Performance
 
Faster Container Image Distribution on a Variety of Tools with Lazy Pulling
Faster Container Image Distribution on a Variety of Tools with Lazy PullingFaster Container Image Distribution on a Variety of Tools with Lazy Pulling
Faster Container Image Distribution on a Variety of Tools with Lazy Pulling
 
Understand more about C
Understand more about CUnderstand more about C
Understand more about C
 
用十分鐘 向jserv學習作業系統設計
用十分鐘  向jserv學習作業系統設計用十分鐘  向jserv學習作業系統設計
用十分鐘 向jserv學習作業系統設計
 
Performance Wins with BPF: Getting Started
Performance Wins with BPF: Getting StartedPerformance Wins with BPF: Getting Started
Performance Wins with BPF: Getting Started
 
無線LANデバイスについて(kernelレベル)
無線LANデバイスについて(kernelレベル) 無線LANデバイスについて(kernelレベル)
無線LANデバイスについて(kernelレベル)
 
[JCConf 2023] 從 Kotlin Multiplatform 到 Compose Multiplatform:在多平台間輕鬆共用業務邏輯與 U...
[JCConf 2023] 從 Kotlin Multiplatform 到 Compose Multiplatform:在多平台間輕鬆共用業務邏輯與 U...[JCConf 2023] 從 Kotlin Multiplatform 到 Compose Multiplatform:在多平台間輕鬆共用業務邏輯與 U...
[JCConf 2023] 從 Kotlin Multiplatform 到 Compose Multiplatform:在多平台間輕鬆共用業務邏輯與 U...
 

Similar to Go, meet Lua

Gopenflow demo v1 (english)
Gopenflow demo v1 (english)Gopenflow demo v1 (english)
Gopenflow demo v1 (english)
Hiroaki Kawai
 

Similar to Go, meet Lua (20)

Comparing C and Go
Comparing C and GoComparing C and Go
Comparing C and Go
 
Mender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and GolangMender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and Golang
 
Gopenflow demo v1 (english)
Gopenflow demo v1 (english)Gopenflow demo v1 (english)
Gopenflow demo v1 (english)
 
Why You Should be Using Multi-stage Docker Builds in 2019
Why You Should be Using Multi-stage Docker Builds in 2019Why You Should be Using Multi-stage Docker Builds in 2019
Why You Should be Using Multi-stage Docker Builds in 2019
 
go language- haseeb.pptx
go language- haseeb.pptxgo language- haseeb.pptx
go language- haseeb.pptx
 
Mobile Apps by Pure Go with Reverse Binding
Mobile Apps by Pure Go with Reverse BindingMobile Apps by Pure Go with Reverse Binding
Mobile Apps by Pure Go with Reverse Binding
 
Go. why it goes v2
Go. why it goes v2Go. why it goes v2
Go. why it goes v2
 
Why Go Lang?
Why Go Lang?Why Go Lang?
Why Go Lang?
 
GTG30: Introduction vgo
GTG30: Introduction vgoGTG30: Introduction vgo
GTG30: Introduction vgo
 
Docker and Go: why did we decide to write Docker in Go?
Docker and Go: why did we decide to write Docker in Go?Docker and Go: why did we decide to write Docker in Go?
Docker and Go: why did we decide to write Docker in Go?
 
Go lang
Go langGo lang
Go lang
 
Getting started with go - Florin Patan - Codemotion Milan 2016
Getting started with go - Florin Patan - Codemotion Milan 2016Getting started with go - Florin Patan - Codemotion Milan 2016
Getting started with go - Florin Patan - Codemotion Milan 2016
 
Go. Why it goes
Go. Why it goesGo. Why it goes
Go. Why it goes
 
Golang workshop - Mindbowser
Golang workshop - MindbowserGolang workshop - Mindbowser
Golang workshop - Mindbowser
 
Introduction to Go
Introduction to GoIntroduction to Go
Introduction to Go
 
Go for Mobile Games
Go for Mobile GamesGo for Mobile Games
Go for Mobile Games
 
Golang introduction
Golang introductionGolang introduction
Golang introduction
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golang
 
Golang from Scala developer’s perspective
Golang from Scala developer’s perspectiveGolang from Scala developer’s perspective
Golang from Scala developer’s perspective
 
10 reasons to be excited about go
10 reasons to be excited about go10 reasons to be excited about go
10 reasons to be excited about go
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

Go, meet Lua

  • 1. Go, meet Lua Using Lua in Go and vice-versa! André Burgaud @andreburgaud 4/15/2020
  • 2. You 💖Go... Why would you need Lua? ● NGINX (OpenResty) ● Wireshark ● Nmap ● Pandoc ● HAProxy ● Redis ● Roblox ● Rockbox ● SciTE ● LÖVE
  • 3. Agenda ● CGO ○ Using C from Go (inline code and separate files) ○ Using Go from C (export) ● Embedding Lua in Go (CGO) ○ Executing a lua script from Go ○ Building a basic Lua REPL in Go ● Extending Lua with Go ○ LuaJIT FFI ● Using a Lua Interpreter in Go
  • 5. CGO - Inline C code in GO Go code C code in Go comments main.go I’m using C code!
  • 6. CGO - Inline C code in GO (code/demo) package main /* #include <stdio.h> void hello() { printf("Hello from C!n"); } */ import "C" // No new line between block comment and 'import "C"' func main() { C.hello() }
  • 7. CGO - Separate *.h and *.c Files Go code C code in Go comments Go code header files in Go comments main.go hello.h hello.a exe hello.c ① ②
  • 8. CGO - Separate *.h and *.c Files (code/demo) package main // #include <stdlib.h> // #include <hello.h> import "C" import ( "unsafe" ) func main() { C.hello() name := C.CString("GoMN") defer C.free(unsafe.Pointer(name)) C.print(name) }
  • 9. main.c CGO - Using Go from C (export) Include golib.h Go code with Exported functions main.go golib.h golib.so a.out ① ② -buildmode=c-shared golib.so ③ a.out No fair! C is using me!
  • 10. CGO - Using Go from C (code / demo) package main import ( "C" "os" ) //export Pwd func Pwd() *C.char { d, err := os.Getwd() if err != nil { return C.CString("Error") } return C.CString(d) } func main() {}
  • 12. Executing a Lua Script in Go Go code C code in Go comments Go code Executes hello.lua header files and CGO linking in Go comments main.go lua*.h liblua.a exe lauxlib.h I’m using Lua C code! hello.lua
  • 13. Executing a Lua Script in Go ● CGO ☠ … Again ● Problem with C Macros - #define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL) ● Unsafe pointers (need to free allocated memory)
  • 14. Building a Lua REPL in Go Go code C code in Go comments Go code Executes REPL loop and Interpretes Lua instructions header files and CGO linking in Go comments main.go lua*.h liblua.a exe lauxlib.h I’m using Lua C code! >>> print “hello”
  • 15. Building a Lua REPL in Go ● Here we CGO ☠ … Again ● Problem with C Macros - #define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL) ● Unsafe ● Hard to debug
  • 17. Extend LuaJIT with Go Go code with Exported functions main.go golib.so ① ② -buildmode=c-shared $ luajit getcwd.lua /a/b/c/d $ getcwd.lua I’m happy to give a hand to my friend Lua
  • 18. Extend LuaJIT with Go ● LuaJIT FFI ● Extend Lua to include functions not available in the interpreter STL ● Example: current working directory ● In Go: os.Getwd() ○ Export function in Go ○ Use the FFI module available in LuaJIT (calling external C functions) ○ Add C declaration ○ Call the Go function (LuaJIT sees it as a C function)
  • 19. Export Function in Go (same as C example) package main import "C" import ( "os" ) //export Pwd func Pwd() *C.char { d, err := os.Getwd() if err != nil { return C.CString("Error") } return C.CString(d) } func main() {}
  • 20. Using a Lua Interpreter in Go
  • 21. Lua Interpreter in Go 💖 ● https://github.com/yuin/gopher-lua ● DoString() ● DoFile() ● Base64 (Bi-directional)
  • 22. Lua Interpreter in Go 💖 Go code C code in Go comments 💘 Import gopher-lua Go code Executes and extends lua code main.go
  • 23. Go plugin ● Allows creating modular Go programs ● Allows reusing “plugins” across multiple programs ● https://golang.org/pkg/plugin/ $ go build -buildmode=plugin
  • 24. Ideas 💡 ● Configuration files ● Expose internal APIs ● Extension/Customization (games) ● Templating language (HTML, XML, next ML or JSON…) ● Filtering text processing (pandoc) ● ...
  • 25. Summary ● Quick review of CGO ● Embed Lua in Go (CGO) ● Extend LuaJIT with Go (FFI) ● Embed and Extend with a Lua interpreter written in Go ● More ideas to explore
  • 26. Go Online Resources ● https://github.com/andreburgaud/meetup-golang-lua Source code ● https://golang.org/cmd/cgo/ Command cgo ● https://nick.groenen.me/posts/plugins-in-go-18/ Plugins in Go 1.8 ● https://medium.com/learning-the-go-programming-language/writing-modular-g o-programs-with-plugins-ec46381ee1a9 Writing Modular Go Programs with Plugins ● https://docs.google.com/document/d/1nr-TQHw_er6GOQRsF6T43GGhFDelr AP0NqSS_00RgZ Go Execution Modes
  • 27. Lua Interpreters in Go ● https://github.com/Azure/golua A Lua 5.3 engine implemented in Go (MIT) ● https://github.com/Shopify/go-lua A Lua VM in Go (MIT) ● https://github.com/yuin/gopher-lua GopherLua: VM and compiler for Lua in Go (MIT) ● https://github.com/milochristiansen/lua A Lua 5.3 VM and compiler written in Go (Zlib)
  • 28. Go Books ● https://nostarch.com/blackhatgo Black Hat Go ● https://www.gopl.io/ The Go Programming Language ● https://www.packtpub.com/programming/mastering-go-second-edition Mastering Go
  • 29. Lua Online Resources ● https://www.lua.org/ Lua Web Site ● https://luajit.org/ The LuaJIT Project ● https://www.oreilly.com/content/learn-lua-from-javascript-part-1-an-introductio n-to-lua/ Learn Lua from JavaScript, part 1: An introduction to Lua
  • 30. Lua Books ● https://www.lua.org/pil/ Programming in Lua ● https://www.packtpub.com/application-development/lua-quick-start-guide Lua Quick Start Guide
  • 31. Other Resources ● https://love2d.org/ LÖVE ● https://github.com/love2d/love LÖVE
  • 32. Attributions ● Lua Logo: By Alexandre Nakonechnyj (Grafik-Design) und Lua-Team (PostScript-Code) - svg from PostScript Source (see below) created from Lumu, Public Domain, https://commons.wikimedia.org/w/index.php?curid=37714918 ● Gopher: By Takuya Ueda (https://twitter.com/tenntenn). Licensed under the Creative Commons 3.0 Attributions license, https://github.com/golang-samples/gopher-vector
  • 33. License ● Copyright © 2020 by Andre Burgaud https://burgaud.com ● Released under https://creativecommons.org/licenses/by/4.0/