简体   繁体   中英

Is there any functions like "require" in Squirrel-lang?

I try to import some package using "require"... because of the Squirrel-lang coming from Lua.

But I found that both there is nonthing in both "squirrel3" and "sqstdlib3"..

So I do it like this :

// foo.nut

local foo = {}

return foo
// main.nut

local foo = loadfile("foo.nut")

foo.bar()

Also, there is no "dostring"

..... Do I need to implement a package manager myself?

dofile should do the trick ( documented here ).

I tried the following:

// foo.nut
local foo = {function bar(){print("bar!")}}
return foo

and

// main.nut
local foo = dofile("foo.nut")
foo.bar()

then got this result:

C:\Users\me\squirrel3\bin>sq.exe main.nut
bar!
C:\Users\me\squirrel3\bin>

尝试查看https://github.com/inlife/squirrel-require ,可能对您有用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM