Comments (10)
As i said originally:
require simply isn't supported.
not true, i tried with some of dirs shown in error message and they worked..
There is a huge difference between "it works" and "it is supported". I'll repeat: This is not supported - it should never work, the existing behavior is a bug. Some people wish it was [supported] (there is a ticket for this), but it's currently not. And there is also a ticket to "break" it fully as it's a security risk - and not supported. If require simply never worked period, all the confusion would be gone.
from tic-80.
require
simple isn't supported. All your code has to be placed in the single main file.
from tic-80.
require
simple isn't supported. All your code has to be placed in the single main file.
I may misunderstand, but I think it does, see #2352
from tic-80.
I never used it, not sure I can help but I try anyway:
Did you look at https://github.com/nesbox/TIC-80/wiki/Using-require-to-load-external-code-into-your-cart ? From what I understand the libraries should be in TIC-80/lua/module.lua
file.
Also, I think current directory in TIC-80 is always TIC-80
and not where your cart is or where you cd
#775
However, note that the use of require
could be disabled in future update: #2352
from tic-80.
require
simple isn't supported. All your code has to be placed in the single main file.
not true, i tried with some of dirs shown in error message and they worked... the problem reported here is require
doesn't work with files in tic80 command console current working directory specifically
it seems like tic80 embedded lua only sees the folder where tic80.exe
executable is, and doesn't know/care about tic80 console virtual environment, so the required files are not found
Did you look at https://github.com/nesbox/TIC-80/wiki/Using-require-to-load-external-code-into-your-cart ? From what I understand the libraries should be in
TIC-80/lua/module.lua
file.
yes i tried what that wiki page says and doesn't work (maybe worked in a previous tic80 version)... and for regular lua files other than modules or libraries (e.g. grouplng similar functions, etc.) should work in tic80 command console "cwd" (current working directory, shown in prompt synbol), or the dir where current cart were loaded
Also, I think current directory in TIC-80 is always
TIC-80
and not where your cart is or where youcd
#775
i agree with @moonlit in that this behavior is confusional, prone to provoke errors and should be fixed
However, note that the use of
require
could be disabled in future update: #2352
require
lua function could be very useful, i think it should be fixed in its security issues (the right way) instead being disabled (the fast and lazy way)... check my comment there for more details: #2352 (comment)
from tic-80.
i am using this dirty workaround (it bothers, should load files in same directory without the need of doing these tricks):
- create the subdirectory
<tic80-install>/project-name
- place all lua files here, ex.:
project-main.lua
,functions.lua
project-main.lua
is the file that has header comments,TIC()
function, and others
- create the cartridge file
<tic80-carts>/project-cart.tic
with just this content:
require('project-name.functions') -- will map to "<tic80-install>/project-name/functions.lua"
require('project-name.project-main') -- main file at LAST because include also execute files
- edit files in
<tic80-install>/project-name
with zerobrane or another external editor - when pass to production, concatenate all lua files and run in tic console:;
import code joined-files.lua
, and save
from tic-80.
@joshgoebel ok
from tic-80.
the behaviour indeed can be a bit erratic: for some computers, i've had to add the following line to my main.lua
for require to work:
package.path = package.path..";C:/path/to/your/directory/?.lua"
It adds your working directory to Lua's package.path so Lua can find your files.
from tic-80.
@borbware : as i thought config.cart
is loaded frist any cartridge, i tried to set this permanently by typing config
command and adding this line in code editor:
package.path='%APPDATA%/com.nesbox.tic/TIC-80/?.lua;%APPDATA%/com.nesbox.tic/TIC-80/?/init.lua;'..package.path
THEME=
{
CODE =
{
...
...
but didn't worked :( ... is there any way to do this permanently? (i think it should come from stock)
@TimotheeGreg : i think the instructions in the page you posted are wrong ( https://github.com/nesbox/TIC-80/wiki/Using-require-to-load-external-code-into-your-cart#where-to-locate-our-module-files )
there it says "Open up tic80 and at the console type folder" and create a lua
subfolder there, but after using require()
with a non existing file, the traceback shows me all paths lua tried, but doesn't show lua
subfolder inside tic80 carts folder, but instead it shows a lua
subfolder inside tic80.exe
executable folder... changing the start folder in tic80 shorccut didn't worked either
from tic-80.
i found a better workaround that works:
as a response to my previous response @TimotheeGreg , i put together these 2 facts:
- edit "start folder" in tic80 shortcut, to
%APPDATA%/com.nesbox.tic/TIC-80
- traceback show package.path with
.\?.lua
and.\?\init.lua
(universally ".\" stands for "current folder")
when i edit tic80.exe shortcut "start folder" as shown above, and add require('req-test')
to cart code editor, external edition works for lua files (carts_folder)/req-test.lua
and (carts_folder)/req-test/init.lua
=D
from tic-80.
Related Issues (20)
- Android: TIC80 (PRO) not showing virtual gamepad every second run HOT 6
- Associate .tic files with TIC-80 on macOS
- TIC-80 doesn't start properly on Windows XP unless forced to `--soft` HOT 1
- New release soon / more frequent releases? HOT 3
- The "X button to enter surf" needs a better input check HOT 6
- Better import screen error messages HOT 1
- Tiles in map editor does not update after editing tile HOT 1
- Scaling issue on web export on mobile
- Native Apple Silicon version and Black Borders
- `--fs` accepts files, not just folders; errors follow
- Command line not fully visible when using past commands
- [Libretro] iOS support HOT 2
- Using surf, 'close game' should go back to surf and not console HOT 1
- Mouse sprite and ram aren't linked
- keyword 'of' in javascript is not colored
- Segmentation fault HOT 6
- Segfault when saving after running HOT 2
- cccccbcrknfjjukihcdgfkchudgregenkrjrldtvjdfl
- tic80 behaves differently when run from source checkout HOT 2
- Keys getting stuck when grabbing the window
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tic-80.