store global bytecode
This commit is contained in:
parent
5a5d18ca0e
commit
dadc6f13f7
@ -2,6 +2,7 @@ package functions
|
||||
|
||||
import (
|
||||
"maps"
|
||||
"sync"
|
||||
|
||||
"Moonshark/functions/http"
|
||||
|
||||
@ -24,3 +25,20 @@ func GetAll() Registry {
|
||||
|
||||
return registry
|
||||
}
|
||||
|
||||
var (
|
||||
storedBytecode []byte
|
||||
bytecodeMutex sync.RWMutex
|
||||
)
|
||||
|
||||
func SetStoredBytecode(bytecode []byte) {
|
||||
bytecodeMutex.Lock()
|
||||
defer bytecodeMutex.Unlock()
|
||||
storedBytecode = bytecode
|
||||
}
|
||||
|
||||
func GetStoredBytecode() []byte {
|
||||
bytecodeMutex.RLock()
|
||||
defer bytecodeMutex.RUnlock()
|
||||
return storedBytecode
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ end
|
||||
-- HTTP MODULE FUNCTIONS
|
||||
-- ======================================================================
|
||||
|
||||
function http.createServer(options)
|
||||
function http.newServer(options)
|
||||
options = options or {}
|
||||
|
||||
local serverID = moonshark.http_create_server()
|
||||
@ -119,7 +119,7 @@ end
|
||||
|
||||
-- Convenience function to create and start server in one call
|
||||
function http.listen(addr, handler)
|
||||
local server = http.createServer()
|
||||
local server = http.newServer()
|
||||
|
||||
if handler then
|
||||
server:get("/*", handler)
|
||||
|
18
moonshark.go
18
moonshark.go
@ -59,8 +59,22 @@ func main() {
|
||||
fmt.Fprintf(os.Stderr, "Warning: failed to add script directory to package.path: %v\n", err)
|
||||
}
|
||||
|
||||
// Execute the script
|
||||
if err := state.DoFile(scriptPath); err != nil {
|
||||
// Read script file
|
||||
scriptContent, err := os.ReadFile(scriptPath)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error reading script file '%s': %v\n", scriptPath, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Compile script to bytecode
|
||||
bytecode, err := state.CompileBytecode(string(scriptContent), scriptPath)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error compiling '%s': %v\n", scriptPath, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Execute the compiled bytecode
|
||||
if err := state.LoadAndRunBytecode(bytecode, scriptPath); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error executing '%s': %v\n", scriptPath, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user