store global bytecode
This commit is contained in:
parent
5a5d18ca0e
commit
dadc6f13f7
@ -2,6 +2,7 @@ package functions
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"maps"
|
"maps"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"Moonshark/functions/http"
|
"Moonshark/functions/http"
|
||||||
|
|
||||||
@ -24,3 +25,20 @@ func GetAll() Registry {
|
|||||||
|
|
||||||
return 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
|
-- HTTP MODULE FUNCTIONS
|
||||||
-- ======================================================================
|
-- ======================================================================
|
||||||
|
|
||||||
function http.createServer(options)
|
function http.newServer(options)
|
||||||
options = options or {}
|
options = options or {}
|
||||||
|
|
||||||
local serverID = moonshark.http_create_server()
|
local serverID = moonshark.http_create_server()
|
||||||
@ -119,7 +119,7 @@ end
|
|||||||
|
|
||||||
-- Convenience function to create and start server in one call
|
-- Convenience function to create and start server in one call
|
||||||
function http.listen(addr, handler)
|
function http.listen(addr, handler)
|
||||||
local server = http.createServer()
|
local server = http.newServer()
|
||||||
|
|
||||||
if handler then
|
if handler then
|
||||||
server:get("/*", handler)
|
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)
|
fmt.Fprintf(os.Stderr, "Warning: failed to add script directory to package.path: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute the script
|
// Read script file
|
||||||
if err := state.DoFile(scriptPath); err != nil {
|
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)
|
fmt.Fprintf(os.Stderr, "Error executing '%s': %v\n", scriptPath, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user